Case Statement syntax in MySQL:-
CASE
WHEN search_condition THEN statement_list
[WHEN search_condition THEN statement_list] ...
[ELSE statement_list]
END CASE
Case Statement syntax in SQL Server 2008:-
Simple CASE expression:
CASE input_expression
WHEN when_expression THEN result_expression [ ...n ]
[ ELSE else_result_expression ]
END
Follow SQL SERVER CASE STATEMENT SYNTAX
I have explained the difference so that users can understand what I am tryng to say here
I have the following code in MySql:-
SELECT sum(case when Year=2014 or purchased=0 then 0 else TC.TOTAL_SP_COST-TC.TOTAL_CP_COST end) as EARNINGs
from TABLE TC
If you see properly the case statement has 2 fields (Year and purchased)
When i tried the same code in MS SQL SERVER 2008,i got a red line under "or" when i tried to add 2 field in case statement in SQL SERVER.
SELECT sum(case (Year or purchased) when 2014 then 0 when 0 then 0 else TC.TOTAL_SP_COST-TC.TOTAL_CP_COST end) as EARNINGs
So the simple question is "Can we add multiple fields in case statement in SQL SERVER ?" IF YES How can we do it ?