-3

I'm trying to implement this two when condition in the case expression but it is just not happening. Please help me fix this?

SELECT 
    BR, CID, TRNDATE, 
    CASE
        WHEN TRNTYPE = '108' THEN -1 ELSE 1 * TrnAmt/100
        WHEN TRNTYPE = '114' THEN (TrnIntAmt - TrnTaxAmt)/100
    END as TransactionAmount
FROM 
    T_TRNHIST
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
YesB
  • 3
  • 4
  • 5
    When in doubt how a something works, the documentation is a great place to start: [CASE (Transact-SQL)](https://learn.microsoft.com/en-us/sql/t-sql/language-elements/case-transact-sql). – Thom A Oct 22 '19 at 08:10
  • Possible duplicate of [Case in Select Statement](https://stackoverflow.com/questions/14189216/case-in-select-statement) – Prashant Pimpale Oct 22 '19 at 08:10

2 Answers2

4

Query Must be like that

SELECT BR, CID, TRNDATE, 
CASE
    WHEN TRNTYPE = '108' THEN -1 
    WHEN TRNTYPE = '114' THEN (TrnIntAmt - TrnTaxAmt)/100
    ELSE 1 * TrnAmt/100
    END as TransactionAmount
FROM T_TRNHIST

Else condition would come at last once all when done

Mahesh S
  • 373
  • 1
  • 3
  • 19
2

just a little change, move the ELSE to before the END

SELECT BR, CID, TRNDATE, 
CASE
    WHEN TRNTYPE = '108' THEN -1 
    WHEN TRNTYPE = '114' THEN (TrnIntAmt - TrnTaxAmt)/100
    else 1 * TrnAmt/100
END as TransactionAmount
FROM T_TRNHIST
Mazhar
  • 3,797
  • 1
  • 12
  • 29