从上面的示例数据中,我想编写一个查询,如果ExpRow值= 1则将SalesAmount返回为0.0,如果ExpRow值= 2,则返回ExpenseAmount为0.0
答案 0 :(得分:1)
SELECT
ExpRow,
ExpenseDate,
CASE WHEN ExpRow = 2 THEN 0 ELSE ExpenseAmount END AS ExpenseAmount,
CASE WHEN ExpRow = 1 THEN 0 ELSE SalesAmount END AS SalesAmount
FROM
Table
答案 1 :(得分:0)
不确定这是否与您完全相同,但是......
SELECT CASE([ExpRow]) WHEN 1 THEN 0 ELSE SalesAmount END AS 'SalesAmount',
CASE([ExpRow]) WHEN 2 THEN 0 ELSE ExpenseAmount END AS 'ExpenseAmount'
FROM [YOUR_TABLE]