Search code examples
sqlsql-serverdatabaselinked-serveropenquery

Insert statement from a linked server won't insert into the table. What am I missing here?


I'm using SQL Server 2016 to attempt to insert records from couple of tables located on a linked server. I can run the query and pull the data that I'm looking for, but when I attempted to insert it into the table it runs successfully, but no data is inserted into the SQL Server table. Here's my code;

insert into BTGroup (authorizedgroup, itemno)
select custno, prod 
from OPENQUERY(NxtTest, '
select s.custno, p.prod, p.zauthorized
from pub.zics s 
join pub.csp p on s.prod = p.prod
where p.zauthorized = 1
')

I feel like I'm missing something obvious here, but I'm new to working with linked servers so I'm a bit lost. Any help is greatly appreciated.


Solution

  • If you didn't get any error message and receive a message like (20 rows affected) in result window so everything is ok.

    Check the selected database that contains BTGroup table when you are executing the query or change it to the full address. (e.g. MyDatabase.dbo.BTGroup)