Try … Catch … Insert Into

im tryning to insert all the errors that i get from my select statement into an error table but i don´t get this to work.

BEGIN TRY 
    INSERT INTO [database]..[Table]
(
[Column1],
[Column2],
[Column3]
)
SELECT [Column1],[Column2],[Column3] FROM [database]..[SourceTable] 
END TRY
BEGIN CATCH
INSERT INTO [database]..[ErrorTable]
(
[Column1],
[Column2],
[Column3]
)

--What to do here? .... (select the same query as up?)

SELECT [Column1],[Column2],[Column3] FROM [database]..[SourceTable]
END CATCH

Now i would like to see all the errors in my Error Table and all the once that got right in the Table but i dont get this to work?

Thr datatypes of all the fields are the same in source,error and table


Source: sql

Leave a Reply