I have a query which truncates and inserts data from the stored procedure table. However, I am not able to create stored procedure since I have ;With
statement after INSERT INTO
table. The query is below. Can someone please help me?
CREATE PROCEDURE [BC].[TestStoredProc]
AS
BEGIN TRY
set nocount on
set xact_abort on
set ansi_warnings off
set arithabort off
set arithignore on
BEGIN TRAN
TRUNCATE TABLE [S].[sample]
INSERT INTO [S].[sample] ([ColumnID])
;WITH P AS
(
SELECT a, b, c
FROM testtable
)
SELECT PC.columnID
FROM ABC RC
LEFT JOIN BCD CC ON RC.BCD = CC.BCD
LEFT JOIN P PC ON RC.fldClientId = PC.fldPersonID
COMMIT TRAN
END TRY
BEGIN CATCH
IF (XACT_STATE() <> 0)
BEGIN
ROLLBACK TRANSACTION
END;
THROW;
END CATCH
RETURN 0
Error:
Procedure [BC].[TestStorproc], Line 40 [Batch Start Line 0]
Incorrect syntax near ';'