Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql: Check if 1 or more items of one delimited string exist in another

Status
Not open for further replies.

chebil

Programmer
Joined
Oct 10, 2010
Messages
1
Location
GB
Hi all,
Which is the best way to check if an item or more of one delimited string exist in another?
I'd like to pass 2 delimited strings to a UDF and get back TRUE if at least one item of
the first delimited string exists in the second delimited string.

delStr1="US,FR,DE"
delStr2="GB,DE,CA,PL"
delStr3="CN,DK,IT"

UDF_CheckDelimitedStringItems(delStr1,DelStr2)= TRUE
UDF_CheckDelimitedStringItems(delStr2,DelStr3)= FALSE
 
The best way will be to split both strings and check this way:

select * from dbo.fnSplit(@String1, ',') where Value in (select Value from dbo.fnSplit(@String2,',')

Take a look at this blog post
Parsing multiple ranges to SP which gives you several links to the string splitting related blogs.

PluralSight Learning Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top