In SQL SERVER, there’s also a TRY CATCH. Format is as follows
BEGIN TRY
…
END TRY
BEGIN CATCH
…
END the CATCH.
In addition, the WITH statement should be preceded by a semicolon (;) at the end of the previous SQL statement. . For example, in a TRY CATCH, you would have a “;” That is as follows:
BEGIN TRY
;
WITH w AS(
SELECT f1,f2,f3
,ROW_NUMBER() OVER(ORDER BY Id DESC) AS Row
FROM [t1]
WHERE Code=@Code
)
INSERT INTO [t2](
f1,f2,f3
SELECT f1,f2,f3
FROM w WHERE Row>100;
END TRY
BEGIN CATCH
END CATCH;