Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

case statement to replace union all

$
0
0

Need advice on case statement to replace union all

Want to implement case and remove union all

SELECT 
,[MONTH]
,[YEAR]
,[A]
,[B]
,[C]
,[D]
,[E]
,'HELLO' as STRING1
,'HI' AS STRING2
,SUM(E) as metric1
,SUM(D) AS metric2
NULL AS RATE

FROM TAB D1, 
TABLE D2 WHERE (D2.[A]= D1.[A])  
group by 
[MONTH]
,[YEAR]
,[A]
,[B]
,[C]
,[D]
,[E]

UNION ALL


SELECT 
,[MONTH]
,[YEAR]
,[A]
,[B]
,[C]
,[D]
,[E]

,'HELLO' as STRING1
,'HI' AS STRING2
,SUM(B) as metric1
,SUM(C) AS metric2
NULL AS RATE
FROM TAB D1, 
TABLE D2 WHERE (D2.[A]= D1.[A])  
group by 
[MONTH]
,[YEAR]
,[A]
,[B]
,[C]
,[D]
,[E]


Mudassar



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>