你好,
由于你直接case when as 的列不是原表的列,所以无法直接相加,你可以使用with CTE创建一个临时的结果集,然后select这个表中的列,将case when as的列直接相加即可。关于CTE的用法:WITH common_table_expression
(Transact-SQL)
以下是Northwind数据库做的测试,供你参考
1. 直接查询原表[Order Details] 以及结果
SELECT Quantity,
CASE
WHEN Quantity > 30 THEN 40
ELSE 0
END AS Quantity1,
CASE
WHEN Quantity = 30 THEN 30
ELSE 0
END AS Quantity2
FROM [Order Details]

2.用WIth cte 定义临时结果集,再查询相加的列,结果如下
with cte as
(SELECT Quantity,
CASE
WHEN Quantity > 30 THEN 40
ELSE 0
END AS Quantity1,
CASE
WHEN Quantity = 30 THEN 30
ELSE 0
END AS Quantity2
FROM [Order Details])
select Quantity1,Quantity2, (Quantity1+Quantity2) as "Total"
from cte

希望对你有用
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.