Groups | Blog | Home
all groups > sql server new users > january 2007 >

sql server new users : If in SQL?


Barry
1/3/2007 8:04:03 AM
Hi,

You need to use the CASE statement.

e.g

Select Case
When @ClientAge <= 12 Then 'N'
Else 'E'
End

HTH

Barry
Vayse
1/3/2007 3:29:52 PM
Hi
There is a ClientAge field in months. In my query, I'd like to return 'N'
for New if the ClientAge is 12 or less. If over 12, I'd like to display 'E'
for Existing.
How do I do this? I've tried using the IIf statement,
IIF(Client_Type<13, 'N', 'E')
but that doesn't work.
What should I use?
Thanks
Vayse

Roy Harvey
1/4/2007 7:20:34 AM
How exactly is not not working? A syntax error? Wrong results? If
you post the SELECT, preferably with table definitions, someone might
be able to help.

Roy

[quoted text, click to view]
Vayse
1/4/2007 9:52:23 AM
Thanks not working for me. I'm putting the statement the Column part of a
view. I'm guessing I should be doing something else?


[quoted text, click to view]

Vayse
1/4/2007 4:21:40 PM
Thanks guys, got it working now.

[quoted text, click to view]

AddThis Social Bookmark Button