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 |
SQLBoy14
Yak Posting Veteran
70 Posts |
Posted - 2014-08-17 : 23:52:08
|
Hello,I have a select statament:Declare @BusColor varchar(10)Select BusColor, BusDriverFrom BusDatabaseWhere BusColor = @BusColorThese are what in BusDatabase:BusColor BusDriverYellow AndyYellow BryanYellow JimmyBlue TonyBlue JeanI 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
22864 Posts |
Posted - 2014-08-18 : 03:48:25
|
Your WHERE clause should beWhere (BusColor = @BusColor or @BusColor ='All')and you need to pass 'All' as a value if you want data for all colorsMadhivananFailing to plan is Planning to fail |
|
|
SQLBoy14
Yak Posting Veteran
70 Posts |
Posted - 2014-08-18 : 20:27:17
|
Thank you MadhivanaSQLBoy |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-08-19 : 08:33:45
|
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. |
|
|
|
|
|