SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Article: The case for CASE
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 10/05/2000 :  22:59:46  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
We get many questions asking whether it's possible to use an IF clause inside a SELECT statement. Well, not exactly. But you can use CASE to do the exact same thing.

Article Link.

coho
Starting Member

USA
3 Posts

Posted - 10/31/2001 :  11:49:37  Show Profile  Reply with Quote
But CASE still cannot do nondeterministic parsing. How can I do this...

CASE aTable.NumColumn
WHEN aTable.NumColumn > 0 THEN 'Positive'
WHEN aTable.NumColumn < 0 THEN 'Negative'
ELSE 'Exactly Zero'
END


Go to Top of Page

izaltsman
A custom title

USA
1139 Posts

Posted - 10/31/2001 :  11:57:56  Show Profile  Send izaltsman an AOL message  Send izaltsman an ICQ Message  Reply with Quote
Actually, you almost had it:

SELECT CASE
WHEN aTable.NumColumn > 0 THEN 'Positive'
WHEN aTable.NumColumn < 0 THEN 'Negative'
ELSE 'Exactly Zero'
END

Go to Top of Page

r937
Posting Yak Master

Canada
112 Posts

Posted - 10/20/2003 :  14:57:41  Show Profile  Visit r937's Homepage  Reply with Quote
the last two examples in the article are missing the END keyword

rudy
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

USA
4137 Posts

Posted - 10/20/2003 :  16:02:33  Show Profile  Visit graz's Homepage  Reply with Quote
Heh. Three years those have been wrong. Thanks for pointing it out. And it's fixed.

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000