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
 General SQL Server Forums
 New to SQL Server Programming
 How do I?

Author  Topic 

kifeda
Posting Yak Master

136 Posts

Posted - 2007-03-12 : 11:40:37
Hello All,

I have s small problem: I have a list menu that allows a user to select multiple options. How do I write a select statement to return the values? So for example:

If the user selects two values from the drop down menu and it submits to query string, the value looks like this

userid=89&userid=34

Now I want to display the users, but only for 89 and 34. How do I write a select statement to pull just those values? Can I use a select in? I thought I could do it like this:

Select * from users where userid like select in varUserid

but that doesn't work. What should Id o?

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-03-12 : 11:46:12
You'll need to a select statement like this

SELECT *
FROM Users
WHERE UserID IN (89, 34)

You can't just pass the value of the variable (userid=89&userid=34) in the SQL statement, you'll need to write some code in your application language to get the IDs out of the variable and create the SQL statement text so that you pass the query above to SQL Server.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-12 : 12:03:20
You can accumulate those userids as a comma-separated value in a string variable and in the database, you could just parse out those value into a temp table and use it in the SELECT statement.

For more discussion on CSV splitting, see this:
[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=CSV,Split[/url]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -