Reputation: 49
I have two comma separated strings:
abc,cde,efg
abc,efg
Is there any way that I can find intersection of the values i.e. any of the substrings in string1 that match the substrings in string2?
I have tried to split the string on the basis of a comma and find any string from the left side matches the substring of the right string then true else false.
Upvotes: 0
Views: 69
Reputation: 272106
You can do so like this:
SELECT s1.value
FROM STRING_SPLIT('abc,cde,efg', ',') AS s1
CROSS JOIN STRING_SPLIT('abc,efg', ',') AS s2
WHERE s1.value = s2.value
-- returns ('abc') and ('efg')
Upvotes: 1