Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert into from 2 different database 1

Status
Not open for further replies.

CortexWayne

Programmer
Jan 14, 2003
18
CA
Hello, I'm trying to put data into PIpgF from PEbv Where there is no PipgF row containing the value 2 in ipgSource

INSERT INTO [C:\KPA\PGenet].PIpgF
(CodeFemel, DateEven, CodeIpg, IpgRes, IpgRep, IpgSource)
SELECT CodeSiga, DateEven, CodeIpg, IpgRes, IpgRep, 2
FROM [C:\PKPARES].PEbv AS SOURCE
WHERE CodeSiga <> null AND NOT EXISTS (SELECT * FROM [C:\KPA\PGenet].PIpgF
WHERE IpgSource = 2)

Here is the 2 tables structures with value

PIgpF
CodeFemel = 123, 123, 124, 124
DateEven = Date, Date, Date
CodeIpg = 12, 11, 12 , 11
IpgRes = 2.33, 4.3, 2.35, 4.1
IpgRep = 32, 0, 32, 0
IpgSource = 1, 1, 2, 2

PEbv
CodeSiga = 123, 124
DateEven = Date, Date
CodeIpg = 12, 11
IpgRes = 7.7, 7.8
IpgRep = 5, 5

It should give
PIgpF
CodeFemel = 123, 123, 124, 124, 123
DateEven = Date, Date, Date, Date
CodeIpg = 12, 11, 12 , 11, 12
IpgRes = 2.33, 4.3, 2.35, 4.1, 7.7
IpgRep = 32, 0, 32, 0, 5
IpgSource = 1, 1, 2, 2, 2

Any advice is good for me.

Martin L.
 
can you help me understand better these two lines

Where there is no PipgF row containing the value 2 in ipgSource


NOT EXISTS (SELECT * FROM [C:\KPA\PGenet].PIpgF
WHERE IpgSource = 2)

ck1999
 
Perhaps this ?
WHERE CodeSiga NOT IN (SELECT CodeFemel FROM [C:\KPA\PGenet].PIpgF WHERE IpgSource = 2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top