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 |
fonzie
Starting Member
31 Posts |
Posted - 2006-01-05 : 13:38:40
|
I have a dropdown box that has 51 items to choose from: all 50 states plus the word "ALL". How would you form an SQL statment if the user chose ALL? For example:SELECT * FROM MYTABLE WHERE STATE = DROPDOWNLIST.SELECTEDITEM.VALUE |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-01-05 : 13:40:44
|
select * from tbl where (state = @state or @state = 'all') and ...==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
fonzie
Starting Member
31 Posts |
Posted - 2006-01-05 : 13:45:19
|
How about : where (state = @state or @state = '%%') ?The thing is I want no discrimination of states if user has selected "ALL" from the dropdownlist. |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-01-05 : 13:51:36
|
nr's suggestion accomplishes your requirement because you're comparing the variable to 'all' not the state column values:select * from tbl where (state = @state or @state = 'all') Be One with the OptimizerTG |
|
|
fonzie
Starting Member
31 Posts |
Posted - 2006-01-05 : 14:40:04
|
oh, so that's the same as selecting from a table where "7" = "7", you get em all? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2006-01-05 : 14:50:58
|
You got it!Be One with the OptimizerTG |
|
|
|
|
|