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 |
|
amitranjan
Starting Member
45 Posts |
Posted - 2008-12-18 : 04:59:09
|
| Can I use Control Statements like if else and Switch case in sql query? If yes? How?. Lets take an example i am passing param as date in sp and i m running a select query there and want to implement if-else or switch condition there.Please guide me...It will be highly appreciated.Thanks and regardsamit Ranjan |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-18 : 05:25:18
|
| use switch case is not present in sql , u have to use casecase when date = @date then 1 else 0 end AS aliasnameu have follow like this for case statement |
 |
|
|
amitranjan
Starting Member
45 Posts |
Posted - 2008-12-18 : 05:55:25
|
| Can you provide me some sort of exampleamit Ranjan |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-18 : 06:05:25
|
| DECLARE @tab table(active bit)insert into @tab select 1 union all select 0 union allselect 1select * from @tabselect case when active = 1 then 'active' else 'inactive' end as status from @tabexample on case function |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2008-12-18 : 06:25:22
|
| Please have a look at books on line u will get plenty of examples on case statementsJai Krishna |
 |
|
|
|
|
|