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 |
|
ChadLewis
Starting Member
4 Posts |
Posted - 2000-12-01 : 04:34:13
|
| This is a tricky one. I want to pass a stored procedure three comma separated strings of primary key ids to search on. Any of these can be blank.I use an sp called spSys_ReturnTokens to convert the string into a temporary table. This all works, if i specify both @search1 and @search2. but if i dont then i have to set the temporary table to contain every record in the database.There must be an easier way. And preferably not using temporary tablesMy code so far is this:declare @search1 varchar(50)declare @search2 varchar(50)IF @search1 is null BEGIN SELECT @search1='' ENDIF @search2 is null BEGIN SELECT @search2='' ENDCREATE TABLE #search1 (MID int NULL)CREATE TABLE #search2 (MID int NULL)set nocount onBEGIN INSERT INTO #search1 exec spSys_ReturnTokens searchtable1 ENDBEGIN INSERT INTO #search2 exec spSys_ReturnTokens searchtable2 END SELECT DISTINCT * FROM Searchtable1 INNER JOIN Searchtable2 ON Searchtable1.UniqueID = Searchtable2.UniqueID WHERE Searchtable1.UniqueID IN (select UniqueID from #search1 AND Searchtable2.UniqueID IN (select UniqueID from #search2DROP TABLE #search1DROP TABLE #search2SET NOCOUNT OFF |
|
|
|
|
|