You might try this with two derived tables you combine with an INNER JOIN
:
DECLARE @s1 NVARCHAR(100)='java,.net,oracle';
DECLARE @s2 NVARCHAR(100)='some1,.net,java';
WITH s1Splitted AS
(
SELECT LTRIM(RTRIM(A.B.value('.','nvarchar(max)'))) AS Part
FROM
(SELECT CAST('<x>' + REPLACE(@s1,',','</x><x>') + '</x>' AS XML) AS y) AS x
CROSS APPLY x.y.nodes('/x') AS A(B)
)
,s2Splitted AS
(
SELECT LTRIM(RTRIM(A.B.value('.','nvarchar(max)'))) AS Part
FROM
(SELECT CAST('<x>' + REPLACE(@s2,',','</x><x>') + '</x>' AS XML) AS y) AS x
CROSS APPLY x.y.nodes('/x') AS A(B)
)
SELECT *
FROM s1Splitted AS s1
INNER JOIN s2Splitted AS s2 ON s1.Part=s2.Part
This can easily be packed into an inline table valued function which you call as easy as
SELECT * FROM dbo.MyFunction(@s1,@s2);
Attention
If you are expecting input containing the three characters of evil you should replace <, > and &
with < > and &
, otherwise the XML-split approach would break...
EDIT
As you are looking for the existance of any equality only, a simple COUNT
on the result would suffice. You might declare your function as BIT
and do this evaluation on function's level, or return the result-set (which would be my approach) and do the evaluation outside...