SQL Query to Insert records in Table from one SQL Server instance to another

Before proceeding with the insert logic make sure following points:

1. Make sure that the target SQL Server is added in sys.servers through SQL Query :
          select * from sys.servers

2. if the target SQL Server is not in sys.servers you can add it by using sp_addlinkedserver stored procedure, Such as sp_addlinkedserver '<SEREVR NAME>'

Execute the following SQL Query:

 INSERT INTO dbo.[TableName]
   SELECT *
   FROM [ServerNAme].[DataBaseName].dbo.[TableName]

SIMILAR SCENARIO CAN BE USED FOR UPDATE AS BELOW:


update dbo.SalesTable
 set custAccount = ST2.CustAccount
 from dbo.SalesTable ST1
 inner join [ServerNAme].[DataBaseName].dbo.SalesTable ST2
 on ST1.SalesID= ST2.SalesId

Comments

Popular posts from this blog

D365: SSRS Report Development/ Customization

D365: X++ code to add custom lookup on worker to show specific workers team workers only

Error message when you log on to a Microsoft Dynamics AX 4.0 client: "You are not a recognized user of Microsoft Dynamics AX"