Mssql connects multiple databases and integrates data into one table

Source: Internet
Author: User
Mssql connects multiple data and integrates data into a table * method 1 $ SQL & quot; createprocOtherConnSQLasbegin & nbsp; selectSQLNCLI, Server (local ); trusted_Connect mssql connects multiple tables and integrates data into one table.
*/
// Method 1

$ SQL = "create proc OtherConnSQL
As
Begin
Select id = u_id, name = u_name, tel = u_tel from openrowset ('sqlncl', '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 ('sqlcl', 'server = (local); Trusted_Connection = yes; ', 'select id, c_name, c_tel from CBA. dbo. CU_TABLE ') as
End ";


// Method 2

$ Sql1 = "create proc OtherConnSQL
As
Begin
Select id = u_id, name = u_name, tel = u_tel from openrowset ('sqlncl', 'server = (local); Trusted_Connection = yes; ', 'select u_id, u_name, U_password, u_tel from ABC ...... ";

// Method 3: This is not connected

$ Sql2 = "create proc OtherConnSQL
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 ('sqlncl', '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 ('sqlncl', 'server = (local); Trusted_Connection = yes; ', 'select id, c_name, c_tel from CBA. dbo. CU_TABLE ') as
End

";

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.