从上面的示例数据中,我想编写一个查询,如果 ExpRow 值 = 1,则将 SalesAmount 返回为 0.0,如果 ExpRow 值 = 2,则将 ExpenseAmount 返回为 0.0
问问题
27 次
2 回答
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
于 2012-06-22T06:29:11.143 回答
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]
于 2012-06-22T06:26:52.063 回答