Hi,
Is it possible (using T-SQL) to delete a row from one table and insert
it into another? e.g. I have a table dbo.employee, an employee leaves,
so I delete their record, but want to place it into dbo.employee_old

Signature
Gerry Hickman (London UK)
Andrew J. Kelly - 21 Jul 2008 23:21 GMT
Sure but not in one statement.
BEGIN TRAN
INSERT INTO dbo.employee_old (column list)
SELECT Column list from dbo_employee WHERE Employee_ID = xxx
DELETE FROM dbo.employee WHERE Employee_ID = xxx
COMMIT TRAN
Of course you may want to put some error logic in there but that is the
general idea.

Signature
Andrew J. Kelly SQL MVP
Solid Quality Mentors
> Hi,
>
> Is it possible (using T-SQL) to delete a row from one table and insert it
> into another? e.g. I have a table dbo.employee, an employee leaves, so I
> delete their record, but want to place it into dbo.employee_old
Dan Guzman - 22 Jul 2008 01:40 GMT
> Is it possible (using T-SQL) to delete a row from one table and insert it
> into another? e.g. I have a table dbo.employee, an employee leaves, so I
> delete their record, but want to place it into dbo.employee_old
If you are using SQL 2005, you can use the OUTPUT clause. For example:
DELETE FROM dbo.employee
OUTPUT deleted.*
INTO dbo.employee_old
WHERE employee_id = 1

Signature
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
> Hi,
>
> Is it possible (using T-SQL) to delete a row from one table and insert it
> into another? e.g. I have a table dbo.employee, an employee leaves, so I
> delete their record, but want to place it into dbo.employee_old
Andrew J. Kelly - 22 Jul 2008 15:39 GMT
Good point Dan.

Signature
Andrew J. Kelly SQL MVP
Solid Quality Mentors
>> Is it possible (using T-SQL) to delete a row from one table and insert it
>> into another? e.g. I have a table dbo.employee, an employee leaves, so I
[quoted text clipped - 12 lines]
>> into another? e.g. I have a table dbo.employee, an employee leaves, so I
>> delete their record, but want to place it into dbo.employee_old
Gerry Hickman - 22 Jul 2008 21:55 GMT
> Good point Dan.
Interesting!
Thanks for the ideas; I've just realized this database is on SQL 2000,
but hope to have it moved to SQL 2005 soon, and the OUTPUT clause looks
useful.

Signature
Gerry Hickman (London UK)
Sha Anand - 22 Jul 2008 06:41 GMT
Why not use triggers :)
- Sha Anand
> Hi,
>
> Is it possible (using T-SQL) to delete a row from one table and insert
> it into another? e.g. I have a table dbo.employee, an employee leaves,
> so I delete their record, but want to place it into dbo.employee_old
Gerry Hickman - 22 Jul 2008 21:56 GMT
> Why not use triggers :)
Thanks, I'll have a look at triggers in the BOL.

Signature
Gerry Hickman (London UK)