Dasblinkenlight's solution is a nice one to the problem, BTW.
I normally build a temp table and just run the data into that. Using an insert or an update.
I know it seems (both suggested solutions) like a lot of overhead to get one piece of data out but that's really what it takes.
create table #Value (
set @command = 'insert into #value (val) SELECT top 1 voterid FROM tblCamp_CT WHERE ' +@Query
set @voter_id=(select top 1 val from #Value)
You could also research sp_executesql for your project.
this works, for example:
declare @voter_id int , @query varchar(max), @command nvarchar(4000)
SET @Command = 'SELECT top 1 @voter_id = voterid FROM tblCamp_CT WHERE ' + @Query
set @parm ='@voter_id int output '
exec sp_executesql @command,@parm ,@voter_id out
select @voter_id test
As you can see the sp_executesql gives you another option.
Some of this depends on what your personal flavor is toward a given solution.
Give a man a mug, he drinks for a day. Teach a man to mug...
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.