Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Detecting which tables/fields in view.

Author  Topic 

lotek
Starting Member

42 Posts

Posted - 2005-10-03 : 13:41:31
I want to write a select statement that can get a result set of each field & parent table in a view.

So something like

field1 table1
field2 table1
field3 table2

etc..

Possible?


Thanks
Matt

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-04 : 00:37:35
Is this?

Select T1.field1,T1.field2,T2.field3 from Table1 T1 inner join Table2 T2 on T1.column1=T2.Column1

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

lotek
Starting Member

42 Posts

Posted - 2005-10-04 : 12:16:35
I should have been more clear, something like the information_schema.columns except i also want to return the original table name of the columns.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-05 : 00:47:26

Select column_Name, Table_Name from Information_Schema.columns order by 2, 1


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-10-05 : 00:53:10
since you do know which column came from which table you can
concatenate each column value with e.g. 'Table1' or 'Table2'
like..

Select ('Table1.' + T1.field1) as 'field1','Table1' + ...

each field will be considered as string type or

you can change the column name to [ as 'table1-field1'] and each column can still retain their own datatypes


quote:
Originally posted by lotek

I should have been more clear, something like the information_schema.columns except i also want to return the original table name of the columns.



--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -