先生想要在单个网格视图中从不同的数据库中检索数据 [英] sir want to retrieve data from different data base in a single gridview

查看:60
本文介绍了先生想要在单个网格视图中从不同的数据库中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生想要在单个网格视图中从不同数据库中检索不同数据库中的数据。



i已为此编写此代码。



sir want to retrieve data from different data base of diffrent tabe in a single gridview.

i have written this code for this.

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

推荐答案

试试这个希望这对你有用。



Try liks this hope this will work for you.

      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


如果表格中的列与使用UNION或UNION ALL相同



来自DATABASE1.DBO.TABLE的SELELCT COLUMNNAME

UNION ALL / UNION

来自DATABASE1.DBO的SELELCT COLUMNNAME。表



您的工作完成
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


这篇关于先生想要在单个网格视图中从不同的数据库中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆