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

complex stored procedure

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
GB
Hi,

I need to write a stored procedure that will add all the fields of one table (say table 1) to another table (table 2) and then delete the fields from table 1 that have just been added. can i do all this in a stored procedure? i think i need to use a join but unuure how

Thanks for your help
 
do you mean records? Or do you want to create a new table 2 with the same field names?

INSERT INTO Table2 (SELECT * FROM Table1)

then

DELETE FROM Table1

Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
I guess you want to delete from the first table what you just copied to the second table... use a join.

Something like this

INSERT INTO Table2(idRecord, vchRecordData)
SELECT idRecord, vchRecordData
FROM Table1

DELETE Table1 FROM Table1
JOIN Table2 ON Table1.idRecord = Table2.idRecord
WHERE Table2.idRecord is Not Null



Just make sure you have a field that you can use to check what data to delete, a field that is identical in both tables. (So do not try to use 2 identity/autonumber columns, the can and probably will become different over time)




"In three words I can sum up everything I've learned about life: it goes on."
- Robert Frost 1874-1963
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top