question

rjford11 avatar image
rjford11 asked

Pivot Using CASE Statement

I have the following data:

763b44e57b39-16e5bb772ac November Monthly Mailer MM_10 191201-1 2019-12-01 00:00:00.000 2020-01-01 00:00:00.000
763b44e57b39-16e5bb772ac November Monthly Mailer MM_10 191208-2 2019-12-01 00:00:00.000 2020-01-01 00:00:00.000
763b44e57b39-16e5bb772ac November Monthly Mailer MM_10 191215-3 2019-12-01 00:00:00.000 2020-01-01 00:00:00.000
763b44e57b39-16e5bb772ac November Monthly Mailer MM_10 191222-4 2019-12-01 00:00:00.000 2020-01-01 00:00:00.000
763b57fe9950-16dac7db279 October Monthly Mailer MM_10 191001-1 2019-10-01 00:00:00.000 2019-11-01 00:00:00.000
763b57fe9950-16dac7db279 October Monthly Mailer MM_10 191008-2 2019-10-01 00:00:00.000 2019-11-01 00:00:00.000
763b57fe9950-16dac7db279 October Monthly Mailer MM_10 191015-3 2019-10-01 00:00:00.000 2019-11-01 00:00:00.000
763b57fe9950-16dac7db279 October Monthly Mailer MM_10 191022-4 2019-10-01 00:00:00.000 2019-11-01 00:00:00.000
763b57ff55b7-16dad4ef4b8 November Monthly Mailer MM_10 191101-1 2019-11-01 00:00:00.000 2019-12-01 00:00:00.000
763b57ff55b7-16dad4ef4b8 November Monthly Mailer MM_10 191108-2 2019-11-01 00:00:00.000 2019-12-01 00:00:00.000
763b57ff55b7-16dad4ef4b8 November Monthly Mailer MM_10 191115-3 2019-11-01 00:00:00.000 2019-12-01 00:00:00.000
763b57ff55b7-16dad4ef4b8 November Monthly Mailer MM_10 191122-4 2019-11-01 00:00:00.000 2019-12-01 00:00:00.000
763b5803a370-16dcb7cfd7e 11th Anniversary Celebration SBR $15 Sky Ute Loot 2019-11-01 00:00:00.000 2019-11-02 00:00:00.000

I Need to create Pivot using CASE statement so that the results looks like:

763b44e57b39-16e5bb772ac MM_10 191201-1 MM_10 191208-2 MM_10 191215-3 MM_10 191222-4
763b57fe9950-16dac7db279 MM_10 191001-1 MM_10 191008-2 MM_10 191015-3 MM_10 191022-4

What's the best way to do this using CASE statement?

case-statement
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·

Can you post your data as a T-SQL create table / insert script so that we can see more clearly what we're dealing with?

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.