Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 string list as a parameter for a data adapter

Author  Topic 

drey
Starting Member

10 Posts

Posted - 2004-09-01 : 10:47:49
I am trying to read a table:
select * from table1
where letter in (@parameter)
@parameter is a list like 'a', 'b', 'c'
the select statement is in a dataadapter. when i try to fill a dataset I get nothing. but if i remove the parameter and had code the list in the select statement, I get the expeted rows in my dataset.

I tried set the list with the outter ' and without it.
thank you

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-01 : 10:54:15
thats becasue it doesn't work this way.
if you're building a statement in .net build it without parameters:
string stmt = "select * from table1 where letter in (" + parameters + ")"
sqlCommand.Text = stmt

othwerwise u need to do it via dynamic sql.
http://www.sqlteam.com/item.asp?ItemID=4619

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-09-01 : 10:59:08
And there's always Bill's article....

http://www.sqlteam.com/item.asp?ItemID=11499

Got to be one of the top 5 questions asked...

Why is that?



Brett

8-)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-01 : 11:02:31
even better... :))

because IN is so popular when you're starting sql. i used it a lot in my very early days... didn't you brett?


Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

drey
Starting Member

10 Posts

Posted - 2004-09-01 : 11:22:44
to spirit1
fmi only...
why do you say "IN" is popular for beginners?
what is better?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-01 : 12:59:35
well of course it all depends on the situation.
using exists is usually faster. and a lot of things can be solved with joins instead of IN(...). joins are also faster.
but that's only my opinion.

and i can't remember when was the last time i used an IN(..) in an app.

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -