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

PIVOT Help

$
0
0

I don't know why but the PIVOT function escapes my comprehension.

All I am trying to convert the following :

DateResponseCount

2012-03Sent50
2012-03Opened36
2012-04Sent45
2012-04Opened15

into the following :

DateSentOpened

2012-0350 36
2013-0445 15

My code is simplified to be easier to read, but is essentially the same.

WITH my_CTE ( Date, Response, Num) AS ( SELECT Date, Response, Num

FROM TABLE_IN_MY_DATABASE ) SELECT Date, [Sent], [Opened] FROM ( SELECT Date, Response, Num FROM my_CTE) A PIVOT ( SUM(Num) FOR Response IN ( [Sent], [Opened]) ) AS unpvt

With said code I end up getting :

DateSentOpened

2012-0350 NULL
2012-03NULL 36
2012-0445 NULL
2012-04NULL 15

Thanks for all the help.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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