3

我来自 MySQL 背景,所以请在这里多多包涵。使用 MSSQL Server 2008,我正在编写一个包含 IFF 语句的查询。我收到以下错误。

"Msg 102, Level 15, State 1, Line 8
Incorrect syntax near '='."

我的查询如下所示:

SELECT
    a.[storeno],
    a.[Description],
    a.[transactiondate],
    a.[amount] AS 'pos',
    b.[amount] AS 'ecc',
    a.[amount] - b.[amount] AS 'difference',
    IIF(a.amount = b.amount,'BALANCED','UNBALANCED') AS 'result',
    GETDATE()
FROM
    [POS_REPORT].[dbo].[Txn_Daily_Totals] a
LEFT JOIN
    [POS_REPORT].[dbo].[SAP_FI_INBOUND_DAILY_TOTALS] b ON
    a.[storeno] +
    a.[transactiondate] =
    b.[storeno] +
    b.[transactiondate]

我尝试了很多不同的方法,但无法做到这一点。我用过

IF
BEGIN
END
ELSE
END

和案例。都给了我不同的错误。请帮我。

4

2 回答 2

3

你可以这样写:

case when a.amount = b.amount then 'BALANCED' else 'UNBALANCED' end as result

代替

IIF(a.amount = b.amount,'BALANCED','UNBALANCED') AS 'result'
于 2012-11-20T09:35:22.180 回答
2

IIF 在 SQL server 2008 中没有实现。它是 2012 版本中的新功能。

于 2012-11-20T09:39:13.590 回答