修复SQL Server中关键字“何时”错误附近的“语法不正确”吗?

2019-10-22 sql-server

我正在尝试在case表达式中实现这两个when条件,但这只是没有发生。请帮我解决这个问题?

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

Answers

只需稍作更改,即可将ELSE移至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

查询必须是这样

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

完成后,其他条件将最终一次出现

Related