sp_executesql - What is wrong with my Parameter-string?
I've stared myself blind at this. It started as a more complex procedure, but I've stripped it down to the bare bones, trying to make it run. This is the current code:
DECLARE @sql NVarchar(MAX) = ' CREATE PROCEDURE dbo.Test AS BEGIN SELECT 1, @num; END' EXEC [sp_executesql] @sql, N'@num int', @num = 1;
It simply refuses. It's worth mentioning that if I run the code without the parameter-part (
@sql being the sole parameter to the
sp_executesql function) it runs fine. I've tried other syntax alternatives, such as
EXEC [sp_executesql] @sql, N'@num int', 1;
DECLARE @params NVarchar(1000) = '@num int'; EXEC [sp_executesql] @sql, @params, 1;
What is wrong with my parameter-specification?
Edit 1: Included error-message
Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'PROCEDURE'.