Hi
sp_executesql
sp_executesql is a system stored procedure that you can use in place of "exec" to execute your dynamic sql.
This allows you to have parameters in your dynamic query and
pass them in. The end result is that SQL Server will try to cache the
execution plan for your query giving you some of the advantages of a
fully compiled query.
Usage:
Declare @SQL nVarChar(1000) --N.B. string must be unicode for sp_executesql
SELECT @SQL = 'SELECT * FROM pubs.DBO.Authors WHERE au_lname = @AuthorName'
Exec sp_executesql @SQL, N'@AuthorName nVarChar(50)', @AuthorName = 'white'
EXEC
This is normal exexcute statemnet in Sql server
Usage :
Declare @SQL VarChar(1000)
SELECT @SQL = 'Create Table ' + @TableName + '('
SELECT @SQL = @SQL + 'ID int NOT NULL Primary Key, FieldName VarChar(10))'
Exec (@SQL)
thank you