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 |
hbadministrator
Posting Yak Master
120 Posts |
Posted - 2013-05-06 : 12:36:35
|
I have a field that has multiple values I would like to select. it contains 10,20,21,23,90. I am trying to be able to write this out not using a stored procedure. I tried using LIKE and IN but I can only use 1 division at a time. WHERE ([div-code] LIKE @division)End result I would like to get is @division 10, 23 <enter>Data shows me all records that are from Division 10 and 23. |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-05-06 : 12:45:33
|
First of all IN is translated as OR e.g. in(10,23), means 10 or 23, not and. Two ways to do so1)not an optimized approach WHERE ','+@division+',' like ','+[Div-Code]+',' -- If Div-Code is not varchar then you'll need to convert it to varchar e.g. convert(varchar,[Div-Code])2)an Optimize approachDeclare/Create a (temporary) table and convert the CSV parameter value into tabular format. then simply join the temporary table with the actual table based on respective columnsCheersMIK |
|
|
hbadministrator
Posting Yak Master
120 Posts |
Posted - 2013-05-06 : 14:50:26
|
Thank you! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|