Muhammad Shahbaz
Muhammad Shahbaz

Reputation: 49

compare non consecutive substrings in SQL server

I have two comma separated strings:

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

Answers (1)

Salman Arshad
Salman Arshad

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

Related Questions