select with case statement给出错误as

时间:2014-05-05 06:44:13

标签: sql-server-2008 select case

我用案例

写了一个商店程序
SELECT TOP(10000) ORDER,ORDERID,CLIENTNUM,

CASE WHEN ExpArrvDate IS NOT NULL AND ActArrvDate IS NULL THEN 'In Transit'
ELSE
  CASE WHEN ActArrvDate IS NULL   THEN 'NOT COME' 
ELSE
 CASE WHEN DRV1NUM IS NOT NULL THEN 'WILL Come'
ELSE
  CASE WHEN PICKEDUP IS NOT NULL THEN 'Picked By JOHN '
ELSE
  CASE WHEN DROPTIME IS NOT NULL THEN 'Dropped Off'
AS OrderDeatils

FROM CTRTABle

我在这个陈述中做错了你能不能帮助我

1 个答案:

答案 0 :(得分:1)

您需要END每个CASE

SELECT TOP(10000) ORDER,ORDERID,CLIENTNUM,

    CASE WHEN ExpArrvDate IS NOT NULL AND ActArrvDate IS NULL THEN 'In Transit'
    ELSE
      CASE WHEN ActArrvDate IS NULL   THEN 'NOT COME' 
    ELSE
     CASE WHEN DRV1NUM IS NOT NULL THEN 'WILL Come'
    ELSE
      CASE WHEN PICKEDUP IS NOT NULL THEN 'Picked By JOHN '
    ELSE
      CASE WHEN DROPTIME IS NOT NULL THEN 'Dropped Off' 
    END END END END END -- Added line. Added END for each CASE
    AS OrderDeatils

    FROM CTRTABle