Tsql SQL Server T-SQL案例错误

Tsql SQL Server T-SQL案例错误,tsql,sql-server-2000,Tsql,Sql Server 2000,我在T-SQL Server 2000案例中遇到错误。非常感谢您的反馈 错误是Msg 156,级别15,状态1,第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 orde

我在T-SQL Server 2000案例中遇到错误。非常感谢您的反馈

错误是Msg 156,级别15,状态1,第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

也许你的代码之间有一个看不见的字符,
在不选择“复制”或“过去”的情况下方便地重写scrpit。

这对我来说很好,运行脚本作为“在客户和订单上创建”并在此处粘贴,可能还有一些示例数据?我没有收到语法错误。你确定你准确地复制了代码吗?我会在字段之间查找缺少的逗号或多个逗号。您忘记了case语句的else子句,case when c.linkid=x.linkid然后x.orderitem else null end as orderitem,如果c.linkid=x.linkid,则x.orderdate else为空,则结束为orderdate@AlexBlokh我在SQL 2008中尝试了这个查询,它似乎是有效的:我认为SQL 2000和2008之间CASE语句的语法没有变化