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 2012 Forums
 Transact-SQL (2012)
 Select 'All'
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SQLBoy14
Yak Posting Veteran

USA
51 Posts

Posted - 08/17/2014 :  23:52:08  Show Profile  Reply with Quote
Hello,

I have a select statament:
Declare @BusColor varchar(10)


Select BusColor,
BusDriver
From BusDatabase
Where BusColor = @BusColor

These are what in BusDatabase:
BusColor BusDriver
Yellow Andy
Yellow Bryan
Yellow Jimmy
Blue Tony
Blue Jean

I know how to set @BusColor to either Yellow Blue but how do make the parameter will select all instead Yellow or Blue?

Thank you all










SQLBoy

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 08/18/2014 :  03:48:25  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Your WHERE clause should be

Where (BusColor = @BusColor or @BusColor ='All')


and you need to pass 'All' as a value if you want data for all colors

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SQLBoy14
Yak Posting Veteran

USA
51 Posts

Posted - 08/18/2014 :  20:27:17  Show Profile  Reply with Quote
Thank you Madhivana

SQLBoy
Go to Top of Page

gbritton
Aged Yak Warrior

857 Posts

Posted - 08/19/2014 :  08:33:45  Show Profile  Reply with Quote
I used something like this before:


WHERE @BusColor in (BusColor, '%')


using a percent sign as a wildcard (since that is what it means in the SQL LIKE operator). So, if you want 'all', pass a percent sign.
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.15 seconds. Powered By: Snitz Forums 2000