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

时间:2019-10-22 08:01:30

标签: 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

2 个答案:

答案 0 :(得分:4)

查询必须是这样

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

完成后,其他条件最终就会出现

答案 1 :(得分:2)

稍作改动,将ELSE移至END之前

 selectedRow: any;
  selection = new SelectionModel<PeriodicElement>(true, []);
  displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
  dataSource = ELEMENT_DATA;

  deleteUser(){
    console.log(this.selectedRow)
  }
}