snippetsqlModerate
How can I execute a stored procedure whose name is in a variable?
Viewed 0 times
storedcanwhoseprocedurenamehowvariableexecute
Problem
Given a variable that contains a stored procedure name:
How can I execute the stored procedure (without passing in any arguments)?
DECLARE @stored_procedure_name varchar(512);
SET @stored_procedure_name = 'some_stored_procedure_name';How can I execute the stored procedure (without passing in any arguments)?
Solution
You can use the variable directly:
Please see the BOL Reference on
exec @stored_procedure_name;Please see the BOL Reference on
EXECUTE.Code Snippets
exec @stored_procedure_name;Context
StackExchange Database Administrators Q#46980, answer score: 14
Revisions (0)
No revisions yet.