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 |
|
kaisdd
Starting Member
17 Posts |
Posted - 2004-11-14 : 07:13:08
|
| hey,for a search tool on my website i have a stored procedured wich uses a list of search words as input params, build a parameterized sql string and execute it with sp_executesqlsp_executesql, returns records found (IDs only)at a second step i would like to save the record ids as a comma separated list in a search result table. i´m using this table as a cache when the user pages trough his search result.i have puzzled about the second step for hours but it won't work.how can i save the result from sp_executesql in a variable or something? could´t anybody help?thaaaaaaaaaanks! |
|
|
kaisdd
Starting Member
17 Posts |
Posted - 2004-11-14 : 08:12:16
|
| i fixed it outi combine the ids in the selectthe proc now returns a output param in the form 1,2,3,4 etc...DECLARE @rtnVal VarChar(1000)SET @rtnVal = ''SET @strSQL = ' SELECT @rtnVal = @rtnVal + CONVERT(VARCHAR, NewsID, 12) + "," FROM ' + @strSearchTable + ' WHERE ' + @strSQL + @strSearchFilterEXEC sp_executesql @strSQL, N'@Search nVarChar(128),@rtnVal VarChar(1000) OUTPUT', @strSearchText, @rtnVal OUTPUTSELECT @rtnVal |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-11-14 : 13:17:41
|
| That will give a spare comma at the end - to get rid of itSET @rtnVal = nullSET @strSQL = ' SELECT @rtnVal = coalesce(@rtnVal + '', '', '''') + CONVERT(VARCHAR, NewsID, 12) FROM '==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
kaisdd
Starting Member
17 Posts |
Posted - 2004-11-15 : 03:22:14
|
| yes, thank you |
 |
|
|
kaisdd
Starting Member
17 Posts |
Posted - 2004-11-15 : 12:57:02
|
| öhm... there is another question where i stuckis it somehow posible to build up a dynamic variable namei split up my search words and save them to variables@strSearchWord1@strSearchWord2@strSearchWord3etc...i do some more operations on these variables later and if i use more than 3 searchwords its a lot of ugly an repeating codeis it posible, to do all this in a loop an append the number only?table vars are not so good, because later in sp_executesql i have to append the variablesEXEC sp_executesql @strSQL, N'@Search1 VarChar(128), @Search2 VarChar(128),@strResultIDs VarChar(8000) OUTPUT, @RecordCount Int OUTPUT', @strSearch1, @strSearch2, @strResultIDs OUTPUT, @RecordCount OUTPUTthank you in advance |
 |
|
|
|
|
|
|
|