August 21, 2006 at 11:29 am
Hello,
I have a little issue that I'm trying to resolve that may be simpler than I'm making it. So here goes...
I have a sql statement listed below:
select * from tablename
where ID in (2,3)
I want to make this statement more flexible so I can use a variable instead of the (2,3):
declare @var varchar(10)
set @var = ‘2,3’
select * from tablename
where ID in (@Var)
This statement returns no records. When the variable is set to a single value such as 2 or 3, the statement
returns data for those records matching a value of 2 or 3.
What I am doing wrong here? Should I get rid of the IN operator all together?
Some notes on the table:
ID is datatype int and contains values of 0-3. Values of 0 and 1 are invalid for this statement.
Thanks in advance,
GP
August 21, 2006 at 11:52 am
http://www.sommarskog.se/dynamic_sql.html
N 56°04'39.16"
E 12°55'05.25"
August 21, 2006 at 11:56 am
I wish I could wish dynamic sql...but it is frowned on at my work. Any other ideas?
August 21, 2006 at 12:41 pm
August 21, 2006 at 2:05 pm
the split function worked well...thanks alot
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply