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 |
|
kmdavisjr
Starting Member
2 Posts |
Posted - 2007-11-13 : 14:40:37
|
| I am trying to use a simple case statement:SELECT BudgetAccountID, Initial_Budget_Amount, case Initial_Budget_Amount when > '0' then 'yes' else 'no' end as test FROM BudgetSummaryI keep getting an Msg 102, Level 15, State 1, Line 1Incorrect syntax near '>'. error.I've tried removing the ticks from the zero, and casting the Initial_Budget_Amount value as int but I still keep getting the error. I've tried to use other boolean operators as well (=, >=, NOT, etc.) and get the same error. What am I missing?Thanks |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-11-13 : 14:42:52
|
the syntax isCASE WHEN <something> THEN <Something> ELSE <Somethingelse> ENDcase when Initial_Budget_Amount > '0' then 'yes' else 'no' end as test Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2007-11-13 : 14:54:19
|
From handy dandy BOL:Simple CASE function:CASE input_expression WHEN when_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] END Searched CASE function:CASE WHEN Boolean_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] END [Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
kmdavisjr
Starting Member
2 Posts |
Posted - 2007-11-13 : 15:05:15
|
Boy, I feel stupid! Thanks Dinakar!quote: Originally posted by dinakar the syntax isCASE WHEN <something> THEN <Something> ELSE <Somethingelse> ENDcase when Initial_Budget_Amount > '0' then 'yes' else 'no' end as test Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/
|
 |
|
|
|
|
|