April 25, 2014 at 7:52 am
David Burrows (4/25/2014)
SELECT
'Type'[Type]
,SUM(CASE WHEN code='09' THEN Amt/100 ELSE 0 END) AS [Col1]
,SUM(CASE WHEN code='10' THEN Amt/100 ELSE 0 END) AS [Col2]
,SUM(CASE WHEN code='11' THEN Amt/100 ELSE 0 END) AS [Col3]
,SUM(CASE WHEN code='12' THEN Amt/100 ELSE 0 END) AS [Col4]
FROM TEST WHERE (Code BETWEEN '09' AND '12')
This is nice one
April 25, 2014 at 8:02 am
thava (4/25/2014)
hi there, it is almost same with Stuart Davies's but the logic is differentmy solution is avoid the summation two times the other solution using two times grouping and summing
if see the execution plan you are able to see it clearly
hey, sorry abt that, i did not see about summation
April 25, 2014 at 7:31 pm
David Burrows (4/25/2014)
SELECT
'Type'[Type]
,SUM(CASE WHEN code='09' THEN Amt/100 ELSE 0 END) AS [Col1]
,SUM(CASE WHEN code='10' THEN Amt/100 ELSE 0 END) AS [Col2]
,SUM(CASE WHEN code='11' THEN Amt/100 ELSE 0 END) AS [Col3]
,SUM(CASE WHEN code='12' THEN Amt/100 ELSE 0 END) AS [Col4]
FROM TEST WHERE (Code BETWEEN '09' AND '12')
Hello David,
Thanks a lot for this solution. I think this one will do the job for me.
Thank you all for you contribution.
April 26, 2014 at 4:48 am
You're welcome
Far away is close at hand in the images of elsewhere.
Anon.
Viewing 4 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy