I have a query that returns two data sets. select count (*) from pfvcfnh where vcfabr = 'AUDIT' and vcsta1 = 'A' and vcshdt > 20090101 and vcshdt < 20090617 union select count (*) from pfvcfnh where vcfabr = 'AUDIT' and vcsta1 = '01' and vcshdt > 20090101 and vcshdt < 20090617;
The result looks like this.
00001 9479 19254
00001 is the column heading 9479 & 19245 are data.
How can I rewrite the query so the output is in 2 columns?
SELECT [00001] = SUM(CASE WHEN vcsta1 = 'A'
THEN 1 ELSE 0
END)
,[00002] = SUM(CASE WHEN and vcsta1 = '01'
THEN 1 ELSE 0 END)
FROM pfvcfnh
WHERE
vcfabr = 'AUDIT'
and vcshdt > 20090101 and vcshdt < 20090617