Click here to Skip to main content
15,891,903 members

Comments by smodak@ats360.com (Top 9 by date)

smodak@ats360.com 3-Apr-20 6:14am View    
I wanted to achieve the same functionality as excel pivoting using the sql query.
smodak@ats360.com 30-Mar-20 10:30am View    
This is not what I am looking for. I am looking to get Excel pivot result using the only a query.
smodak@ats360.com 6-Apr-17 3:07am View    
Please consider provided example of table structure of A,B and C.
If I write the query as follows
SELECT t2.name as TableReferenced,
t.name AS TableWithForeignKey,
c.name AS ForeignKeyColumn,
object_name(constraint_object_id) as FK_Name
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
inner join sys.tables t2 on fk.referenced_object_id=t2.object_id
where t2.name = 'A'
order by 1, 2

It gives me only table B foreign key reference info. I could not get the C table info. Which are related to table B. There can be n number of hierarchy. I want something like I could provide tables A and C to query and it will give information of B table.
smodak@ats360.com 5-Apr-17 3:06am View    
I have tried many schema combination queries to get the connection between two tables but could not come up with proper solution yet.
smodak@ats360.com 5-Apr-17 3:05am View    
Thanks for reply

I have already tried above query but it is not giving the desire result.
I need the connection between two tables to form a query.