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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem inserting from one table to another

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
Table 'members' has the following fields: MAJOR_KEY, EMAIL

Table 'webMembers' has the following fields: MAJOR_KEY, PASSWORD, EMAIL, ACTIVE

The 'members' table gets updated weekly, and the 'webMembers' table is supposed to have all the same records as the 'members' table. I need to do and insert that takes any new records from 'members' that don't match up with the records already in the 'webMembers' table and inserts them into the 'webMembers' table. Any records that do get inserted into 'webMembers' would just need NULL values for the PASSWORD and ACTIVE fields.

The SQL I'm using isn't accomplishing this task. I get an error: "Column name or number of supplied values does not match the table definition"

Can this only be done if both tables have the same fields?

Anyone know how to do this?

Here's the SQL statement I'm using:
INSERT INTO webMembers
SELECT m1.major_key, m1.email
FROM members m1 LEFT OUTER JOIN webMembers w1 ON m1.major_key = w1.major_key
WHERE w1.major_key IS NULL
 
INSERT INTO webMembers(MAJOR_KEY, EMAIL)
SELECT m1.major_key, m1.email
FROM members m1 LEFT OUTER JOIN webMembers w1 ON m1.major_key = w1.major_key
WHERE w1.major_key IS N

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top