all groups > sql server (alternate) > october 2003 >
You're in the

sql server (alternate)

group:

Problem with variable in T-SQL


Problem with variable in T-SQL s_laha NO[at]SPAM rediffmail.com
10/14/2003 6:29:15 AM
sql server (alternate):
Hi,

I want to find out the project names, for the PROJ table and I know
the Project IDs as a string (comma seperated).

I tried this:

---------------------------
DECLARE @proj_ids varchar(500)

SET @proj_ids='(100,200)'

SELECT PROJ_NAME FROM PROJ WHERE PROJ_ID IN + @proj_ids
------------------------

But this throws the error:
"Incorrect syntax near '+'"

in Query Analyzer.

Could someone please point, what I am doing wrong?
Re: Problem with variable in T-SQL John Bell
10/14/2003 2:56:50 PM
Hi

Check out the excellent article at:
http://www.algonet.se/~sommar/dynamic_sql.html

John

[quoted text, click to view]

Re: Problem with variable in T-SQL Erland Sommarskog
10/14/2003 10:29:51 PM
[posted and mailed, please reply in news]

Surajit Laha (s_laha@rediffmail.com) writes:
[quoted text, click to view]

Yes, you are inventing your own syntax. SQL Server is not clever enough
to understand that.

Although, John recommended one article on my web site, I like to
recommend another. Look at
http://www.algonet.se/~sommar/arrays-in-sql.html#iter-list-of-integers
to see a function that will help you out.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
Re: Problem with variable in T-SQL s_laha NO[at]SPAM rediffmail.com
10/16/2003 9:17:52 PM
Thanks a lot to you people!!!

The article at the URL pointed, was fabulous!
I really liked it and solved a lot of confusions of mine...

Thanks guys.

AddThis Social Bookmark Button