Click here to Skip to main content
15,916,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
sir want to retrieve data from different data base of diffrent tabe in a single gridview.

i have written this code for this.

SQL
SELECT database1.dbo.table1.*, database2.table2.*, database3.dbo.table3.*
FROM database1.dbo.table1 JOIN database2.dbo.table2 ON database1.dbo.table1.hid = database2.dbo.table2.hid JOIN database3.dbo.table3 ON database3.dbo.table3.hid =database2.dbo.table2.hid JOIN database3.dbo.table3 ON database3.dbo.table3 .hid = database1.dbo.table1.hid
Posted
Comments
Praveen Kumar Upadhyay 23-Dec-14 5:45am    
So what is the issue??
Rajiv.net40 23-Dec-14 5:49am    
not working this code...
Sinisa Hajnal 23-Dec-14 6:10am    
Not working how? What error do you get? Don't use * in selects, list only the data you need...also use aliases on the tables, easier to read that way.

Try liks this hope this will work for you.

SQL
      SELECT Distinct T1.Col1,
        T1.Col2,
        T1.Col3,
        T2.col1,
        T2.Col2
        T3.Col1,
FROM database1.dbo.table1 t1
 INNER JOIN database2.dbo.table2  T2
            ON T1.hid = T2.hid
INNER JOIN database3.dbo.table3 T3
            ON T2.hid =T3.hid
 
Share this answer
 
IF COLUMNS IN THE TABLE ARE SAME THEN USE UNION OR UNION ALL

SELELCT COLUMNNAME FROM DATABASE1.DBO.TABLE
UNION ALL/ UNION
SELELCT COLUMNNAME FROM DATABASE1.DBO.TABLE

YOUR JOB IS DONE
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900