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.
| Author |
Topic |
|
DaveBF
Yak Posting Veteran
89 Posts |
Posted - 2011-04-19 : 08:30:36
|
| I have 2 questions.I'm trying to pass in a list of strings as a parameter, as in,SELECT names FROM namelist WHERE city IN('Boston','New York').My first question is how do I use a wildcard for the list of cities? I tried the following which is not right.Select names from namelist where city in ('%')I assume there's some way to do that.My second question is I'm having a really hard time passing in the list of cities as a parameter from my ASP .NET VB code.I tried e.Command.Parameters("@CityList").Value = "'Boston','New York'"and that returned nothing, where I expected it to. I think something's wrong with the quotes.Thanks. |
|
|
DaveBF
Yak Posting Veteran
89 Posts |
Posted - 2011-04-19 : 08:38:50
|
| And I have a 3rd question.If I wanted to use integers in my SELECT IN, is there a way to pass that list in as a single parameter.Select * from namelist where cityNumber in (2,4)Can I pass the list of integers in as a parameter from my VB? |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2011-04-19 : 08:50:54
|
| Ans 1( which is again a question )What you are trying to do using wildcard with list of cities ?Ans 2You can not use Parameters in SQL Queries for IN Operator.For this you will have to go for dynamic SQL or You can create a SQL Statement at your frontend(VB).Instead of using parameter create a string variable by concatenating Values and Execute it as SQL Statement.Ans 3 Same you can do with integer listVaibhav TIf I cant go back, I want to go fast... |
 |
|
|
DaveBF
Yak Posting Veteran
89 Posts |
Posted - 2011-04-19 : 08:54:12
|
quote: Originally posted by vaibhavktiwari83 Ans 1What you are trying to do using wildcard with list of cities ?I was trying to pass in the list thru a parameter, but in some cases accept all cities.Ans 2You can not use Parameters in SQL Queries for IN Operator.For this you will have to go for dynamic SQL or You can create a SQL Statement at your frontend(VB).Instead of using parameter create a string variable by concatenating Values and Execute it as SQL Statement.OK. I can do it that way. Thanks.Ans 3 Same you can do with integer listVaibhav TIf I cant go back, I want to go fast...
|
 |
|
|
|
|
|