我想在寻找TOP 1的子查询中执行select语句,但前提是原始结果为Null。这就是我到目前为止所做的:
,(select TOP 1 Dimension from CUSTINVOICETRANS WHERE invoiceID= #TempCMs.INVOICEID AND [Inv Amt] = LINEAMOUNT
(CASE
WHEN DIMENSION IS NULL THEN
select TOP 1 Dimension from LEDGERTRANS WHERE ledgertrans.voucher = #TempCms.INVOICEID and ABS([Inv Amt])= AMOUNTMST
END)
) AS 'Department'
但我不断收到以下错误消息
第15行,第15行,第1行,第69行 关键字“CASE”附近的语法不正确。 Msg 102,Level 15,State 1,Line 73 ')'附近的语法不正确。
我不知道如何克服它
答案 0 :(得分:2)
要实现您尝试实现的目标,您可以尝试
,ISNULL((select TOP 1 Dimension from CUSTINVOICETRANS
WHERE invoiceID= #TempCMs.INVOICEID AND [Inv Amt] = LINEAMOUNT)
, (select TOP 1 Dimension from LEDGERTRANS
WHERE ledgertrans.voucher = #TempCms.INVOICEID and ABS([Inv Amt])= AMOUNTMST))
AS 'Department'