Question : Get table name from column in a view

Dear experts,

I have several views and I want to be able to determine from what table the columns are originally. If I use the BaseTableName propery then I get the name of the view returned, but I want to have the name of the table that the column actually belongs to returned. Is there a way to achieve this?

Answer : Get table name from column in a view

You can try the following query:

select
v_obj.name as ViewName,
t_obj.name as SourceTable,
t_col.name as SourceColumn
from
sysobjects t_obj,
sysobjects v_obj,
sysdepends dep,
syscolumns t_col
where
v_obj.xtype = 'V'
and dep.id = v_obj.id
and dep.depid = t_obj.id
and t_obj.id = t_col.id
and dep.depnumber = t_col.colid
order by
v_obj.name,
t_obj.name,
t_col.name
Random Solutions  
 
programming4us programming4us