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 |
|
u2envy1
Yak Posting Veteran
77 Posts |
Posted - 2008-11-27 : 07:00:11
|
| How do I add an IF in a select statementIf the following result is True I want a Y in the column & a N if false.I tried this but it does not work.IF (RosterShift.RSH_DayOff_B) THEN 'Y' ELSE 'N'SELECT RosterShift.RSH_DayOff_BFROM Roster |
|
|
bjoerns
Posting Yak Master
154 Posts |
Posted - 2008-11-27 : 07:12:13
|
| You want to change values, not code. So you use the CASE expression, not the IF statement. |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-11-27 : 07:13:11
|
use case statementsyntax is like...CASE input_expression WHEN when_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] END |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-11-27 : 07:14:55
|
An example:select name,CASE type_desc WHEN 'SYSTEM_TABLE' THEN 'Y' ELSE 'N' END as Systemfrom sys.objects Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
bjoerns
Posting Yak Master
154 Posts |
|
|
u2envy1
Yak Posting Veteran
77 Posts |
Posted - 2008-11-27 : 07:20:47
|
| Thx guys....Much appreciated. |
 |
|
|
|
|
|