cancel
Showing results for 
Search instead for 
Did you mean: 

How to execute dynamic SQL in stored procedure

marcelgerr
Explorer
0 Kudos
129

I made a stored procedure like this:

CREATE PROCEDURE SP_EXEC_CREATE_SCRIPT
LANGUAGE SQLSCRIPT
AS
BEGIN
declare statement clob;
SELECT STRING_AGG(TO_NVARCHAR(DEFINITION), '
') FROM SYS.PROCEDURES WHERE SCHEMA_NAME='TEST_SCHEMA' AND PROCEDURE_NAME LIKE 'SP_%') INTO statement FROM DUMMY;
EXEC :statement;
END

but the EXEC is not going to well. Any suggestions are welcome.

Accepted Solutions (0)

Answers (0)