SQL recordset replication?

Results 1 to 2 of 2

Thread: SQL recordset replication?

  1. #1
    Join Date
    Dec 1969

    Default SQL recordset replication?

    I'm stuck trying to transfer information between two databases on the same SQL server with a query. I want it to check and if the data is in the second then not pull it from the first. Is this possible? For instance, I have DB1 and DB2, both have a Table called "RFS" and both have a field called "RFS_Num". I want it to pull the field from the table in DB1 and check if it's in DB2, if it's in DB2 then don't copy it, if it isn't in DB2 then copy it there. Possible or a pipe dream? heh

  2. #2
    Join Date
    Dec 1969

    Default RE: SQL recordset replication?

    Add DB2 as a linked server to DB1 (check Books Online for more info on how to do this)<BR><BR>Then execute the following query (lnk_DB2 is the name you gave to the linked server)<BR><BR>INSERT INTO OPENQUERY(lnk_DB2,&#039;RFS&#039;)<BR>SELECT DISTINCT A.RFS_NUM From DB1.RFS A<BR> LEFT OUTER JOIN <BR> (<BR> SELECT * FROM OPENQUERY(lnk_DB2, &#039;SELECT RFS_NUM FROM RFS&#039;)<BR> ) as B<BR>ON A.RFS_num = B.RFS_num <BR>WHERE B.RFS_num IS NULL<BR><BR>(out of the top off my head, so you might have to tweak it somewhat, but it should give you the general idea)<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts