我有我想用於SAP Crystal報表的此存儲過程。如果變量爲空,則不會過濾的存儲過程
SELECT
t0.DocNum AS ReceiptNo, t2.DocEntry AS InvoiceNo,
t0.DocDate, t1.CheckAct,
t1.CheckNum, t3.AcctName,
CASE
WHEN (t0.CardName IS NULL) THEN t0.Address
ELSE t0.CardName
END AS CustName,
CASE
WHEN ((t1.CheckNum IS NULL OR t1.CheckNum = 0)
AND t0.TrsfrRef IS NULL) THEN 'Cash'
WHEN (t1.CheckNum > 0
AND t0.TrsfrRef IS NULL) THEN 'Cheque'
ELSE 'Transfer'
END AS PayType,
CASE
WHEN (t1.CheckNum > 0 AND t0.TrsfrRef IS NULL) THEN t1.CheckSum
ELSE t0.DocTotal
END AS DocTotal
FROM
ORCT t0
LEFT OUTER JOIN
RCT1 t1 ON t1.docnum = t0.docnum
LEFT OUTER JOIN
RCT2 t2 ON t0.DocEntry = t2.DocNum
LEFT OUTER JOIN
OACT t3 ON t1.CheckAct = t3.AcctCode
WHERE
t0.DocDate BETWEEN @BeginDate AND @EndDate
AND t0.Canceled = 'N'
AND t3.AcctCode = @Account
在最後一行,我已經聲明的變量@Account
可以過濾通過帳號的結果。我希望我的報告能夠工作,以便如果未選擇某個帳戶(空),則會返回所有帳戶結果。
我該如何做到這一點?
任何幫助表示讚賞。