I'm trying to archive rows from one schema to another on the same server using the approach outlined here:
BEGIN TRAN
BEGIN TRY
INSERT INTO foo(col_a,col_b,col_c,recdate)
SELECT col_a,col_b,col_c,recdate
FROM bar
WHERE recdate BETWEEN @startdate AND @enddate
DELETE FROM bar
WHERE recdate BETWEEN @startdate AND @enddate
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRAN
END CATCH
When I just run
SELECT col_a,col_b,col_c,recdate
FROM bar
WHERE recdate BETWEEN @startdate AND @enddate
A number of rows are selected. However, when I run the whole thing, I get back on the Messages tab
(0 row(s) affected)
If I then run just the select again, the records are still present in the source table.
Why might the INSERT...SELECT DELETE return 0 records affected, and how can I correct that?
Aucun commentaire:
Enregistrer un commentaire