我在使用 T-SQL (SQL Server 2000) 的 CASE 上遇到错误。非常感谢任何反馈
错误是 Msg 156, Level 15, State 1, Line 2 关键字“CASE”附近的语法不正确。
--查询如下:
select c.name,c.customerid,c.linkid
,case when c.linkid=x.linkid then x.orderitem end as orderitem
,case when c.linkid=x.linkid then x.orderdate end as orderdate
from customer as c
Inner join
(
Select C.CustomerID, C.LinkID, O.OrderItem,O.OrderDate
From Customer as C
JOIN Orders as O
ON C.CustomerKey=O.OrderKey
WHERE O.OrderDate='mm-dd-yyyy'
) as X
on c.customerid=x.customerid
order by c.customerid
,case when c.linkid=x.linkid then 0 else 1 end asc
,c.linkid