MSSQL connects multiple databases and consolidates data onto a single table

Source: Internet
Author: User
Tags mssql

MSSQL connects multiple database tutorials and consolidates data onto a single table
*/
Method One

$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 ";


Method Two

$sql 1 = "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 ... ';

Method Three, this does not connect

$sql 2= "CREATE proc Otherconnsql as"
Begin
DECLARE @t_id varchar (varchar), @t_name (50), @t_tel varchar

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

";

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.