Even using Sql Server PIVOT you will have to know the Column names before hand, so no luck there, unless you make use of Pivots with Dynamic Columns or Dynamic PIVOT

SQL Server. Join/Pivot/Performance help please
Is encrypting the password hash in database more secure than storing only the hash?

Suppose we store encrypted SHA-256 result with AES instead of hash directly. Is this a good protection from a situation in the future when someone will break one of the algorithms?
