开发者

Should I use sp_executesql or EXEC to run a stored procedure?

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 storedprocname

sp_executesql is better than EXEC (@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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜