当我没有“>”时,此查询运行正常WHEN子句中的符号但是当ProposalDate晚于'2017-04-10 00:00:00.000'时,我需要这个。我不知道为什么我在添加>时收到语法错误进入WHEN条款。
SELECT *,
CASE ProposalDate WHEN > '2017-04-10 00:00:00.000'
THEN (OrderTotal - ProposalWholesalePrice) +
(ProposalWholesalePrice * 1.02)
ELSE OrderTotal
END "New_OrderTotal"
FROM webservices.dbo.DT_Open_Orders_Baseprice
WHERE ProposalSerialNumber = '639036'
答案 0 :(得分:2)
SQL CASE
表达式has two forms:
CASE
表达式和CASE
表达式。简单CASE
,即CASE ProposalDate WHEN ...
不能与比较运算符一起使用;您需要搜索CASE
而不是:
SELECT
*
, CASE
WHEN ProposalDate > '2017-04-10 00:00:00.000'
THEN (OrderTotal - ProposalWholesalePrice) + (ProposalWholesalePrice * 1.02)
ELSE OrderTotal
END "New_OrderTotal"
FROM webservices.dbo.DT_Open_Orders_Baseprice
WHERE ProposalSerialNumber = '639036'
答案 1 :(得分:0)
你有没有试过把" WHEN"在列名之前? 例如:
SELECT *, CASE WHEN ProposalDate > '2017-04-10 00:00:00.000'
THEN (OrderTotal - ProposalWholesalePrice) + (ProposalWholesalePrice * 1.02) ELSE OrderTotal
END "New_OrderTotal" FROM webservices.dbo.DT_Open_Orders_Baseprice WHERE ProposalSerialNumber = '639036'
答案 2 :(得分:0)
简写case
语法不使用任何运算符,只是使用=
条件计算的一系列值。如果要使用其他运算符,则必须使用完整的case
语法:
SELECT *,
CASE WHEN ProposalDate > '2017-04-10 00:00:00.000'
THEN (OrderTotal - ProposalWholesalePrice) +
(ProposalWholesalePrice * 1.02)
ELSE OrderTotal
END "New_OrderTotal"
FROM webservices.dbo.DT_Open_Orders_Baseprice
WHERE ProposalSerialNumber = '639036'