By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE t(id INT)
CREATE PROCEDURE p1
AS
BEGIN
SELECT 1 AS c;
END
CREATE PROCEDURE p2
AS
BEGIN
INSERT INTO t(id)
EXEC p2;
END
BEGIN
DECLARE @isNested BIT = 0;
BEGIN TRY
BEGIN TRANSACTION;
EXEC p2;
ROLLBACK;
END TRY
BEGIN CATCH
-- Msg 8164 An INSERT EXEC statement cannot be nested.
IF ERROR_NUMBER() = 8164 SET @isNested = 1;
ROLLBACK;
END CATCH
SELECT @isNested;
END
(No column name) |
---|
True |
SELECT * FROM t
id |
---|