Plz help me to rectify the error:
Error: Incorrect syntax near the keyword 'As'.
Code:
declare @flag as int;
SET @flag='1';
SELECT Ci.iInstNumber AS InstNo,Ci.dInstDate AS InstDate, CASE WHEN (@flag='1')THEN SUM(Ci.fInstAmount+Ci.fShareProfit) ELSE Ci.fInstAmount As InstAmount END
Incorrect syntax near the keyword As
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Shankar MRank #874 · 2.5K reputationPosted Nov 8, 2012, 11:57 PM EST
Here it is, The Alias name should be given after the CASE.. END statement like,
declare @flag as int;
SET @flag='1';
SELECT 1 InstNo,getdate() AS InstDate,
CASE WHEN (@flag='1')THEN SUM(1+1)
ELSE 2 END as InstAmount
Thanks,
Shankar
anil john153 reputationPosted Nov 9, 2012, 12:12 AM EST