|
Posted by Erland Sommarskog on 07/13/05 12:20
Resant (resant_v@yahoo.com) writes:
> I have a query :
> Exec 'Select * From Receiving Where Code In (' + @pCode + ')'
>
> @pCode will contain more than one string parameter, eg : A1, A2, A3
>
> How can i write that parameters, I try use :
> set @pCode='A1','A2','A3'
> but get an error : Incorrect syntax near ','
EXEC without parentheses is a call to a stored procedure. Wrap the
expression in parathenses to get dynamic SQL:
EXEC(@sql)
But you should not use dynamic SQL for this sort of thing. Have a look
at http://www.sommarskog.se/arrays-in-sql.html#iter-list-of-strings for
a much better way to approach this problem.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Navigation:
[Reply to this message]
|