Maison >base de données >tutoriel mysql >mssql 连接多个数据库并把数据整合到一张表上

mssql 连接多个数据库并把数据整合到一张表上

WBOY
WBOYoriginal
2016-06-07 17:47:191335parcourir

mssql 连接多个并把数据整合到一张表上
*/
//方法一

$sql ="create proc OtherConnSQL
as
begin
    select id=u_id,name=u_name,tel=u_tel from openrowset('SQLNCLI','Server=(local);Trusted_Connection=yes;','select u_id,u_name,U_password,u_tel from ABC.dbo.USER_TABLE') as t
    union all
    select id=id,name=c_name,tel=c_tel from openrowset('SQLNCLI','Server=(local);Trusted_Connection=yes;','select id,c_name,c_tel from CBA.dbo.CU_TABLE') as A
end";


//方法二

$sql1 ="create proc OtherConnSQL
as
begin
select id=u_id,name=u_name,tel=u_tel from openrowset('SQLNCLI','Server=(local);Trusted_Connection=yes;','select u_id,u_name,U_password,u_tel from ABC……";

//方法三,这种没连合

$sql2="create proc OtherConnSQL as
begin
declare @t_id varchar(50),@t_name varchar(50),@t_tel varchar(50)

select @id=u_id,@name=u_name,@tel=u_tel from openrowset('SQLNCLI','Server=(local);Trusted_Connection=yes;','select u_id,u_name,U_password,u_tel from ABC.dbo.USER_TABLE') as t

select @id=id,@name=c_name,@tel=c_tel from openrowset('SQLNCLI','Server=(local);Trusted_Connection=yes;','select id,c_name,c_tel from CBA.dbo.CU_TABLE') as A 
end

";

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn