0

我对这个语句有疑问,在关键字附近出现错误:

CASE [table1.TransType] IN('Accounts Receivable','Customer Sales')THEN table1.Amt 
            ELSE
            CASE WHEN [table1.Billable] IN(0,8,28) THEN table1.Amt 
            CASE WHEN [table1.Billable] IN(1,2,3,21,22,23)THEN table1.RecAmt 
            CASE WHEN [table1.Billable] IN(9)THEN 0                 
            END
            AS NetBilling
4

2 回答 2

2

我相信你的括号可能是问题所在。WHEN在第一种情况下,您也缺少 a 。

这应该有效:

SELECT
CASE WHEN [table1].[TransType] IN ('Accounts Receivable','Customer Sales') THEN [table1].[Amt] 
  ELSE
    CASE
      WHEN [table1].[Billable] IN (0,8,28) THEN [Amt]
      WHEN [table1].[Billable] IN (1,2,3,21,22,23) THEN [table1].[RecAmt]
      WHEN [table1].[Billable] IN (9) THEN 0 END
END AS NetBilling
FROM [table1]
于 2012-08-22T20:00:13.170 回答
0

缺少 3 个 END:所有 CASE 语句都需要一个最终的 END ......所以请注意第一个 CASE !

于 2012-08-22T20:02:20.733 回答