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 - 2014-02-01 : 07:36:22
|
Hi I try to use a delimeted string in a Query like this....DECLARE @Books nVarChar(500)SET @Books = 'Book1,Book2'....WHERE (dbo.Books.BookName IN (@Books)) AND (dbo.Books.Language = 'se') AND (dbo.Books_1.Language = 'gb') Its not working, it only works with one book name... what could be wrong? |
|
magmo
Aged Yak Warrior
558 Posts |
Posted - 2014-02-01 : 11:11:01
|
For some reason WHERE ';'+@Books+';' LIKE '%;'+CAST(dbo.Books.BookID AS VARCHAR(32))+';%' works, I gonna have to use that instead.. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-02 : 01:52:27
|
quote: Originally posted by magmo For some reason WHERE ';'+@Books+';' LIKE '%;'+CAST(dbo.Books.BookID AS VARCHAR(32))+';%' works, I gonna have to use that instead..
it does pattern matching and tries to match ; + BookID + ; within the passed parameter list which is exactly what you wantOnly thing is for large data performance might be an issueso you may need to use a parsing udf and parse values out from delimited parameter list and add a join to it from your tablehttp://visakhm.blogspot.in/2010/02/parsing-delimited-string.htmlhttp://visakhm.blogspot.in/2013/01/delimited-string-split-xml-parsing.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|