I have this stored procedure that I want to use for my SAP crystal report.
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
On the last line, I have declared a variable @Account
that filters results by account number. I want my report to work such that if an account is not selected(null), results of all account numbers are returned.
How do I achieve this?
Any help appreciated.