|
I have the following code querying Users and Roles in a database and I would like to pivot it by user and have Roles across the top with an
Can I do this with a PIVOT statement or do I have to resort to several CASE statements?
(comments are locked)
|
|
Here's a nasty way using dynamic sql +1 Interesting idea but a bit messy. I was hoping it would be simpler than that. I might as well just use CASE statements for the ones I want to see. Thanks for your reply I will leave it unanswered for now to see if anybody else fancies a try.
Mar 04 '10 at 11:48 AM
Ian Roke
well if you know up front the column names, then it's easy, with no need for dynamic sql or multiple
Mar 04 '10 at 11:51 AM
Kev Riley ♦♦
I liked your solution for the dynamicness of it. ;-)
Mar 04 '10 at 12:03 PM
Ian Roke
I just don't like dynamic sql...urgh!
Mar 04 '10 at 12:15 PM
Kev Riley ♦♦
It works well enough which is all I need. Thanks Kev. One thing I would like it to do is output blank instead of NULL. Is this possible? I couldn't fathom it.
Mar 05 '10 at 05:42 AM
Ian Roke
(comments are locked)
|
|
You would have to know which roles you're concerned with before hand (which is always the case with PIVOT), but this should get you there:
(comments are locked)
|

