wdbates
asked on
In SQL 2008 how do I get a Pivot list of columns
I need to list all DISTINCT column names for a list of tables in a Pivot format. I need the column headers to be the actual column names so that I can see which tables are missing the column. Using the first 2 tables, the ChnlngAssess_PTR should have the Question Attempt column (Column 9) as blank. Example below:
table_name RespID LTID UserID ProjectID LevelID SB_Num CourseAttempt TestAttempt QuestionAttempt QType Question RptQuestion Reference
ARTWBT_PTR RespID LTID UserID ProjectID LevelID SB_Num CourseAttempt TestAttempt QuestionAttempt QType Question RptQuestion Reference
ChlngAssess_PTR RespID LTID UserID ProjectID LevelID SB_Num CourseAttempt TestAttempt QType Question RptQuestion Reference
There are 78 DISTINCT columns for this group of tables. I have attached the queries that list the tables, columns and order as well as the list of columns.
ColumnName.xlsx
PivotHelp.sql
table_name RespID LTID UserID ProjectID LevelID SB_Num CourseAttempt TestAttempt QuestionAttempt QType Question RptQuestion Reference
ARTWBT_PTR RespID LTID UserID ProjectID LevelID SB_Num CourseAttempt TestAttempt QuestionAttempt QType Question RptQuestion Reference
ChlngAssess_PTR RespID LTID UserID ProjectID LevelID SB_Num CourseAttempt TestAttempt QType Question RptQuestion Reference
There are 78 DISTINCT columns for this group of tables. I have attached the queries that list the tables, columns and order as well as the list of columns.
ColumnName.xlsx
PivotHelp.sql
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey Scott;
Thanks for the help!
Thanks for the help!
ASKER
Thank you Scott, you've always been a great help.
You're welcome! I'm glad it was useful.
the spreadsheet is just a colun of column names
& here is the sql from the question
Open in new window
I would much rather see you present a simplified problem and expected result because I think you may be disappointedLet's say you have this table
Open in new window
What do you expect as a result? Is it something like this?Open in new window
How would such a layout answer this: "so I can see which tables are missing the column?"missing the column?
or missing a particular value in a particular column?
or missing any value from any column?
I'm just not sure you have defined the question sufficiently.