0 pts.
 EXEC and sp_executesql
Could someone give me a concise summary of the differences between EXEC and sp_executesql? Should we set standards that require the use of one over the other by our developers? Cheers

Software/Hardware used:
ASKED: May 12, 2004  4:52 PM
UPDATED: April 12, 2011  9:30 AM

Answer Wiki:
EXEC runs a procedure within another procedure. This can also be used to execute dynamic SQL. sp_executesql allows you to run dynamic SQL within a batch or procedure. sp_Executesql allows you to pass in variables to the dynamic code, as well as pass values back from the dynamic code. Each has thier use and I won't recommend forcing one or the other. <b>Differnece between sp_executesql and exec</b> exec compiles the code every time and then execute but sp_executesql executes the code without recompiling it.
Last Wiki Answer Submitted:  April 12, 2011  9:30 am  by  Denny Cherry   64,505 pts.
All Answer Wiki Contributors:  Denny Cherry   64,505 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.

 64,505 pts.