You are here: Re: How to Passing Multi Value Parameter in SQL Query « MsSQL Server « IT news, forums, messages
Re: How to Passing Multi Value Parameter in SQL Query

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация