Click to See Complete Forum and Search --> : [RESOLVED] Stored Procedure Help


mataichi
07-19-2007, 03:30 PM
I am writing a stored procedure and at the end I want to do this....

DELETE FROM dbo.zRegDocCollection WHERE zOwnerID=@OwnerID and zRegDocID NOT IN (@RegDocList)

Problem is zRegDocID is a column of type int and @RegDocList is a NVARCHAR that looks like this.... 19,22,23,24,29
It keeps giving me an error saying "Syntax error converting the nvarchar value '19,22,23,24,29' to a column of data type int."

Any ideas how to do this without changing the column type?

Thnx!

mataichi
07-23-2007, 09:03 AM
Finally figured it out. Here is what I did......

set @strSQL='DELETE FROM xxxxxx WHERE xxxxxxxxx
set @nvarSQL = CAST(@strSQL as NVARCHAR(500))
EXECUTE SP_EXECUTESQL @nvarSQL

Also if you are passing any integers in as parameters you need to declare it as a varchar or you could get some cast errors depending on how you use it.