SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Forming SQL statement on results of choices
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

fonzie
Starting Member

31 Posts

Posted - 01/05/2006 :  13:38:40  Show Profile  Reply with Quote
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

United Kingdom
12543 Posts

Posted - 01/05/2006 :  13:40:44  Show Profile  Visit nr's Homepage  Reply with Quote
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.
Go to Top of Page

fonzie
Starting Member

31 Posts

Posted - 01/05/2006 :  13:45:19  Show Profile  Reply with Quote
How about : where (state = @state or @state = '%%') ?
The thing is I want no discrimination of states if user has selected "ALL" from the dropdownlist.
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 01/05/2006 :  13:51:36  Show Profile  Reply with Quote
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 Optimizer
TG
Go to Top of Page

fonzie
Starting Member

31 Posts

Posted - 01/05/2006 :  14:40:04  Show Profile  Reply with Quote
oh, so that's the same as selecting from a table where "7" = "7", you get em all?
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 01/05/2006 :  14:50:58  Show Profile  Reply with Quote
You got it!

Be One with the Optimizer
TG
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000