Hi,
I'm setting up a new data extraction process which will allow the user to pick certain columns, tables and databases to extract data.
I have a stored procedure that brings me back a format like this
ProjectName AccountSpecific SchemaName TableName ColumnName
Test Project N Test Schema Table1 Col1
Test Project N Test Schema Table1 Col2
Test Project N Test Schema Table1 Col3
Test Project N Test Schema Table1 Col4
Test Project N Test Schema Table2 Col1
Test Project N Test Schema Table2 Col14
SELECT
P.ProjectName
,P.AccountSpecific
,S.SchemaName
,T.TableName
,C.ColumnName
FROM
dbo.Projects P
JOIN
dbo.Schemas S ON P.schemaID = S.schemaID
JOIN
dbo.Tables T ON S.schemaID = T.schemaID
JOIN
dbo.Columns C ON T.TableID = C.TableID
How can I pivot this data so I can build a query like this
SELECT
col1
,col2
,col3
,col4
FROM
dbo.Table1
Any ideas on this would be most appreciated, am I going about the design the best way?
I'm setting up a new data extraction process which will allow the user to pick certain columns, tables and databases to extract data.
I have a stored procedure that brings me back a format like this
ProjectName AccountSpecific SchemaName TableName ColumnName
Test Project N Test Schema Table1 Col1
Test Project N Test Schema Table1 Col2
Test Project N Test Schema Table1 Col3
Test Project N Test Schema Table1 Col4
Test Project N Test Schema Table2 Col1
Test Project N Test Schema Table2 Col14
SELECT
P.ProjectName
,P.AccountSpecific
,S.SchemaName
,T.TableName
,C.ColumnName
FROM
dbo.Projects P
JOIN
dbo.Schemas S ON P.schemaID = S.schemaID
JOIN
dbo.Tables T ON S.schemaID = T.schemaID
JOIN
dbo.Columns C ON T.TableID = C.TableID
How can I pivot this data so I can build a query like this
SELECT
col1
,col2
,col3
,col4
FROM
dbo.Table1
Any ideas on this would be most appreciated, am I going about the design the best way?