I have a stored procedure that needs to call a 2nd SP multiple times. The only thing that changes are the parameters to the 2nd SP. Something like this:
SELECT @P1=5, @P2=5
EXEC MyProc @P1, @P2
SELECT @P1=0, @P2=1
EXEC MyProc @P1, @P2
Now if it was dynamic SQL I was running I know sp_executesql would be better than EXEC but since what I’m calling multiple times in actually a SP should I still use sp_executesql or is EXEC like shown above just as good?
Thanks for any help.
Use EXEC like you have above which is the form
EXEC storedprocnamesp_executesqlis better thanEXEC (@sqlstring)generally where you have dynamic SQL, not a stored proc. So because you’re calling a stored proc, the syntax you have is the best way