Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sp_ExecuteSQL vs EXEC()

Author  Topic 

SoftFox
Starting Member

42 Posts

Posted - 2008-02-05 : 05:34:56
Is there any advantage to using sp_ExecuteSQL instead of just EXEC to execute a SQL string? E.g

DECLARE @ExecStr nVARCHAR(300)
SET @ExecStr = 'SELECT TOP 10 * FROM LCSearchRequests'

--both give same result. Is one better than the other?
exec sp_ExecuteSQL @ExecStr

exec(@ExecStr)

sunil
Constraint Violating Yak Guru

282 Posts

Posted - 2008-02-05 : 05:40:39
see this:
http://vadivel.blogspot.com/2006/12/spexecutesql-vs-execute-dynamic.html
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-05 : 08:24:52
A must read article
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SoftFox
Starting Member

42 Posts

Posted - 2008-02-06 : 05:36:08
OK didnt realise about the ability to pass in parameters in sp_ExecuteSQL. that is quite usefull to know.
Go to Top of Page
   

- Advertisement -