Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
magmo
Aged Yak Warrior
558 Posts |
Posted - 2012-08-22 : 09:48:00
|
HiI need to pass a string like this....1;23;4;56and do a search based on that like this...Select * from tblname where id = 1 or id = 23 or id = 4 or id = 56How would I do that? |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-22 : 09:54:17
|
One quick, but perhaps not very efficient approach is as shown in the query below:Select * from tblname where ';'+@String+';' LIKE '%;'+CAST(id AS VARCHAR(32))+';%'; If performance becomes an issue, you would want to split the semi-colon separated string into tokens into a (virtual) table and join with that table. Take a look at Sommarskog's blog for a discussion of the various options: http://www.sommarskog.se/arrays-in-sql-2005.html |
|
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2012-08-22 : 10:16:41
|
It do the job, thank you very much! |
|
|
|
|
|