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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-03-13 : 18:24:40
|
| majnoon writes "Can I put an IF statement in the select part of a query?I have a column selected that contains nulls and I want to set that column to another value where it is nullcan I do it using the following type of querySELECT (IF Offences IS NULL BEGIN 'NO OFFENCES' END)From Criminal_Record" |
|
|
JamesT
Yak Posting Veteran
97 Posts |
Posted - 2002-03-13 : 18:33:14
|
| You can certainly use the case statement. I have never gotten IF to work in select although I have not tried that hard. Sampleselect gender = case when gender = 'M' then 'MALE' when gender = 'F' then 'FEMALE' else 'UNKNOWN' endfrom employees |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-03-13 : 18:42:55
|
| IF can't work in a SELECT statement. IF in SQL Server operates like the IF...THEN statement in Visual Basic, NOT like the IIF() function. CASE works like the IIF() function. |
 |
|
|
joldham
Wiseass Yak Posting Master
300 Posts |
Posted - 2002-03-13 : 23:27:14
|
| Maybe I am missing something, but if you are only checking for Null values then why not use:SELECT IsNull(Offences, 'NO OFFENCES') From Criminal_RecordJeremy |
 |
|
|
|
|
|