exec ('select * from tb')
exec SP_EXECUTESQL
N'select * from tb'
这两个没有区别,只是sp_executesql要求传递的语句是nvarchar,所以必须要N'select...'
另外sp_executesql可以往语句里面传递参数,也可以从语句里面给变量赋值
declare @count int ,@id int
set @id=10
exec SP_EXECUTESQL N'select @count=count(1) from tb where id>@id', N'@count int out, @id int', @count,@id