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 |
Rawler
Starting Member
9 Posts |
Posted - 2010-11-09 : 12:45:28
|
Hi,I am trying to have 4 variables that store 4 selects results (multiple rows results), to use them later in a where clause.Do I have to declare 4 temp tables, fill them, cursor them and store those results into strings and later add them to the where clause? is there an easier method?thanks! |
|
sql-programmers
Posting Yak Master
190 Posts |
Posted - 2010-12-01 : 07:37:07
|
You can use SQL IN clause here.Something like this,SELECT Column1, Column2, Column3, …FROM Table1WHERE Column1 IN (Select ID from #TEMP) Insert all the values to same temp table named #TEMP and use it like this.SQL Server Programmers and Consultantshttp://www.sql-programmers.com/ |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-01 : 07:46:15
|
Are these resultsets created inside the SP?If so then you can populate table variables or temp tables and use them - no need for strings or cursors.If you want to pass them to the SP then it's a bit more restrictive.You could pass them as csv strings and populate table variables from them in the SP or if they are big you could create temp tables and populate with the resultset then call the SP to access the temp tables.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-01 : 08:04:15
|
With v2008 you can also create a user defined table datatype and use that as a parameter to an SP.Not sure if that was available in v2005.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
|
|
|