I have created a stored procedure and am receiving the following error when trying to call it using an exec 'procedure_name' statement. The procedure has a chunk of static SQL code in the first half and then dynamic code for the last half...
calcNums(Param1, Param2, etc...)
--------
DECLARE a bunch of variables
--------
STATIC CODE here
-------
SET @SQL = DYNAMIC CODE
EXEC @SQL
I have the right database connection selected and I created the procedure with the dbo. schema prefix.
If I call the procedure without any parameters then I get an error of...
Procedure or function 'calcNums' expects parameter 'Param1' which was not supplied.
Otherwise it gives me the error...
Could not find stored procedure ' '.
Can anyone give me an idea as to why I am getting this error?
PRINT @SQLorSELECT @SQL? It sounds like the value of @SQL might not be what you expected. - Adam PoradEXEC @sql;vsEXEC(@sql);will still not work, regardless of what string is in@sql. - Aaron BertrandEXEC @sqlto work when the value of@sqlwas set to the stored procedure name without parameters. For example: `set @sql = 'sp_help'. Here's an example on SQLFiddle - Adam Porad