One way to do this is to wrap the query in a SELECT
and then use COALESCE
on the columns you want to replace the null
values:
SELECT [store #],
COALESCE([tender type], '') [Tender Type],
total
FROM
(
SELECT
CASE
WHEN ( Grouping(s.storeid) = 1 )
THEN 'All Stores'
ELSE Isnull(s.storeid, 'UNKNOWN')
END AS [Store #],
CASE
WHEN ( Grouping(b.currencydesc) = 1 )
THEN 'Store #' + s.storeid + ' TOTAL'
ELSE Isnull(b.currencydesc, 'UNKNOWN')
END AS [Tender Type],
Sum(amount) AS Total
FROM rptrs s
JOIN rppay p
ON s.storeid = p.storeid
AND s.receiptno = p.receiptno
JOIN currencies b
ON b.poscurrency = LEFT(p.paytype, 1)
WHERE trsdate BETWEEN @FromDate AND @ToDate
GROUP BY s.storeid, b.currencydesc WITH rollup
) src
Or you can wrap the column in a COALESCE()
without the subquery:
SELECT
CASE
WHEN ( Grouping(s.storeid) = 1 )
THEN 'All Stores'
ELSE Isnull(s.storeid, 'UNKNOWN')
END AS [Store #],
COALESCE(CASE
WHEN ( Grouping(b.currencydesc) = 1 )
THEN 'Store #' + s.storeid + ' TOTAL'
ELSE Isnull(b.currencydesc, 'UNKNOWN')
END, '') AS [Tender Type],
Sum(amount) AS Total
FROM rptrs s
JOIN rppay p
ON s.storeid = p.storeid
AND s.receiptno = p.receiptno
JOIN currencies b
ON b.poscurrency = LEFT(p.paytype, 1)
WHERE trsdate BETWEEN @FromDate AND @ToDate
GROUP BY s.storeid, b.currencydesc WITH rollup