I want to build a
PIVOT table, but I may have to use dynamic SQL unless the
IN clause can be constructed in regular SQL. I want to do something like this:
SELECT * FROM ( SELECT x, y, z... ) srcTable PIVOT ( MIN(srcTable.TimesDownloaded) FOR OrganizationName IN (SELECT CONCAT('Download_', OrganizationName) FROM AdamUser GROUP BY OrganizationName) ) pivotTable
So when I
AdamUser and prefix
Download_, that gives me a table whose row values equal the names of the columns I want. This is invalid syntax though. Do I always have to hard-code the
PIVOT column names?