I have a large, messy report to write that joins across 5 tables. There is one column in one table that is being used for several different values--essentially a "tag" column, where the tags are used in creative ways depending on what kind of miscellaneous metadata the users want to use.
As a result, my query for the report returns 3 nearly-identical rows that differ only in the "tag" column; for instance, I might get:
NAME TAG EMAIL
BOB A [email protected]
BOB B [email protected]
BOB C [email protected]
What I'd like to do is split the contents of the TAG column to be returned as 3 separate columns from the query, like this:
NAME A B C EMAIL
BOB A B C [email protected]
So I tried using the SQL SERVER CASE/WHEN functionality to do this; I'm saying, for instance, when the value of the Tag column is "A", return it in column "A"; if it's "B," put it in "B"; etc. I thought this would return the above, but instead it gives me this:
NAME A B C EMAIL
BOB A NULL NULL [email protected]
BOB NULL B NULL [email protected]
BOB NULL NULL C [email protected]
Which is clearly less than ideal.
Any thoughts, geniuses of Stack Overflow?