Re: HowTo: Append data to a table stored in another database?
From: Dan Guzman (guzmanda_at_nospam-online.sbcglobal.net)
Date: 11/02/04
- Next message: mgm: "Re: query using distinct and count"
- Previous message: Renjith Chembakarayil: "Re: complex inserting"
- In reply to: Lidschi: "Re: HowTo: Append data to a table stored in another database?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 1 Nov 2004 23:40:35 -0600
You can use NOT EXISTS to exclude those rows that already exist in the
target table based on your primary key:
INSERT INTO dbnameB..tableb(PKcol, col1,col2,col3)
SELECT col1,col2,col3
FROM dbnameA..tableA a
WHERE NOT EXISTS
(
SELECT *
FROM dbnameB..tableb b
WHERE b.PKcol = a.PKcol
)
-- Hope this helps. Dan Guzman SQL Server MVP "Lidschi" <Lidschi@discussions.microsoft.com> wrote in message news:61D7D680-9DDC-41C8-897A-2BDFEF913626@microsoft.com... > Hi Hari Prasad, > > Problem is that I only want to insert new data from table a to table b, > not > all the data, since the "old" data is already stored in table b. > > "Hari Prasad" wrote: > >> Hi, >> >> Specify column list in your Insert statement. >> >> Insert into dbnameB.tableb(col1,col2,col3) select col1,col2,col3 from >> dbnameA.tableA >> >> >> -- >> Thanks >> Hari >> SQL Server MVP >> >> >> "Lidschi" <Lidschi@discussions.microsoft.com> wrote in message >> news:C69E1D99-B692-4E08-B9A3-04947CD3DAA7@microsoft.com... >> > Hi Newsgroup, >> > >> > I have the following scenario: >> > I have database A with table a and I have database b. I created a >> > stored >> > procedure that transfers table a to database b (now called table b). I >> > inserted two more columns in table b. Now I want to create a stored >> > procedure >> > that appends new data from table a to table b. >> > >> > How can I do this? I tried setting up criterias but nothing did work. >> > Please >> > help me. >> > >> > Thanks and Cheers >> > Lidschi >> > >> >> >>
- Next message: mgm: "Re: query using distinct and count"
- Previous message: Renjith Chembakarayil: "Re: complex inserting"
- In reply to: Lidschi: "Re: HowTo: Append data to a table stored in another database?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|