Thursday, April 8, 2010

SQL – Openquery (3) Delete & Insert

If you have a small (less than 10K. larger dataset will kill your server) set of records on SQL server that you want to pass to the linked server, there is a way to use a staging table.

The DELETE statement will delete all records on the staging table. The INSERT statement will pass your dataset to the staging table.

Then you can use the staging table on the linked server to limit the number of records to come back.

Here is the syntax.

image

Important: the staging table cannot have duplicate records. If it does, the DELETE statement will fail. That’s why it’s important to use DISTINCT in the INSERT statement.

No comments:

Post a Comment