SmileyConspiracy
Technical User
I need to Create a list of column names output by a view. Not a problem using sysobjects and syscolumns. The problem is that I also need to get the tablename for where each column comes from. i.e. if I had the following as a view
Select Person.DomicileId, Person.PersonId from Person Inner Join Domicile on Person.DomicileId = Domicile.DomicileId
I would want the following returned
TableName ColumnName
----------- ---------------------
Person DomicileId
Person PersonId
I've tried using the INFORMATION_SCHEMA.VIEW_COLUMN_USAGE view, but this returns both DomicileIds because one is used in the join! Help!
Select Person.DomicileId, Person.PersonId from Person Inner Join Domicile on Person.DomicileId = Domicile.DomicileId
I would want the following returned
TableName ColumnName
----------- ---------------------
Person DomicileId
Person PersonId
I've tried using the INFORMATION_SCHEMA.VIEW_COLUMN_USAGE view, but this returns both DomicileIds because one is used in the join! Help!