parameter question

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

Is it possible to use a parameter in conjuntion with an IN statement?

For example, if I have the following SQL,
select * from table where key in ('1','2','3')

How can I make the values in the IN be a param? If I do the following.
select * from table where key in (@invals)

I can't make a parameter like so,
param = new sqlparameter("@invals","'1','2','3'")
It simply returns no results.

Is there a way to make a parameter that will work?

Thanks
 
You can't, there is no way to do this as far as i know. You have to
concatenate the strings together for the query.
 
Darn, that's what I figured. Thanks


Marina said:
You can't, there is no way to do this as far as i know. You have to
concatenate the strings together for the query.
 
Yes, this is an interesting approach and I have another I talk about in my
book that uses a Table-type Function to parse the delimited string...

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Thanks. This would work well in stored procedures, but unfortunately I am
using regular sql sentences.
 
Hi

the solution is next ->

DECLARE @smallSQL
SET @smallSQL = "SELECT * FROM Main WHERE Price IN "+@Params
Exec (@smallSQL)
========
Where @Params can be input value of proc like (1,2,3)

:-)

good luck
 
Back
Top