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.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Dynamic SQL question

Author  Topic 

pbs1313
Starting Member

2 Posts

Posted - 2004-10-19 : 18:44:29
Hi. I need some help w/ Dynamic SQL for a stored procedure I need to produce. I'm a web dev, and not a DBA, but this task has fallen to me for this project anyway.

I'm trying to update some values in a table and can't get this to work. Ultimately, I will pass in a comma delimited string for @EntryIDList and an int for @CategoryID.

declare @CategoryID int set @CategoryID = 1
declare @EntryIDList varchar(250)
set @EntryIDList= '1006,1009,1034'

declare @finalist int set @finalist = 10

update dbo.ContestEntry
set ContestStatusID = @finalist
from dbo.ContestEntry e
join dbo.EntryVoteSummery s
on e.EntryID = s.EntryID
where e.CategoryID = @CategoryID
and e.entryid in @EntryIDList

What can I do to fix this error?:
"Line 13: Incorrect syntax near '@EntryIDList'."

Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-10-19 : 18:54:56
http://www.sqlteam.com/item.asp?ItemID=11499

Tara
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-10-19 : 18:57:18
see
http://www.nigelrivett.net/ParseCSVString.html

join dbo.fn_ParseCSVString(@EntryIDList, ',') csv
on e.entryid = convert(int,csv.s)


or
and ',' + @EntryIDList + ',' like '%,' + convert(varchar(20),e.entryid) + ',%'


==========================================
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.
Go to Top of Page
   

- Advertisement -