BEGIN TRY
……
END TRY
BEGIN CATCH
……
END CATCH。
另外,WITH 語句如果前面還有別的SQL語句,應該在前面的SQL語句結尾加上分號";"。比如在這個TRY CATCH裡,就應該在前面加個";",如下:
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;