Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Syntax Error With CASE
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01329827
Message ID:
01329828
Views:
13
You're missing one ) before the THEN clause.
WHEN (t.decTrade_Product_Balance <> 0 AND
>		 ((t.sTrade_Type_Pay_Rec = 'PAY' OR t.sTrade_Type_Pay_Rec = 'REC')
>		 AND t.sTran_Group_CD <> 'MAR')) THEN
Or just remove one extra ( in the OR condition, e.g.
WHEN (t.decTrade_Product_Balance <> 0 AND
>		 (t.sTrade_Type_Pay_Rec = 'PAY' OR t.sTrade_Type_Pay_Rec = 'REC')
>		 AND t.sTran_Group_CD <> 'MAR') THEN
>What's wrong with the CASE statement below? I'm getting "Incorrect syntax near the keyword 'THEN'." on the last CASE.
>
>
>SELECT	ab.sAmark_Bank_Desc,
>		pm.sPayment_Method_Desc,
>		trn.dtInsert_DT,
>		trn.iTrading_Partner_ID,
>		tp.sTP_Name1,
>		trn.iOrder_Hdr_ID,
>		t.sTrade_Type_CD,
>		t.sTran_Group_CD,
>		t.sPayment_Term_CD,
>		trn.decTrans_Amt,
>		CASE sTrans_Type_CD
>			WHEN 'CR' THEN 'Cash Receipt'
>			ELSE 'Cash Disbursement'
>		END AS GroupDesc,
>		CASE sTran_Group_CD
>			WHEN 'MAR' THEN trn.decTrans_Amt
>			ELSE 0
>		END AS iMar,
>		CASE sTran_Group_CD
>			WHEN 'MAR' THEN 0
>			ELSE trn.decTrans_Amt
>		END AS iNotMar,
>
>-- This statement is erroring
>CASE
>	WHEN (t.decTrade_Product_Balance <> 0 AND
>		 ((t.sTrade_Type_Pay_Rec = 'PAY' OR t.sTrade_Type_Pay_Rec = 'REC')
>		 AND t.sTran_Group_CD <> 'MAR') THEN trn.decTrans_Amt
>	ELSE 0
>END AS iProdBal
>
>
>	FROM Transactions trn
>	JOIN Trade t ON t.iTrade_ID = trn.iTrade_ID
>	JOIN Trading_Partner tp ON tp.iTrading_Partner_ID = trn.iTrading_Partner_ID
>	JOIN Payment_Method pm ON pm.sPayment_Method_CD = trn.sPayment_Method_CD
>	LEFT JOIN Amark_Bank ab ON ab.sAmark_Bank_CD = trn.sAmark_Bank_CD
>	WHERE trn.sTrans_Type_CD = 'CR'
>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform