declare @sql nvarchar(4000)
set @sql='select getdate()'
exec (@sql)

核心:exec(sqlcommand)

动态拼接sql命令,然后用exec(sqlcommand)执行该命令

 

 

注:用这个写的存储过程所返回的结果集不知道能不能被客户端代码获得。---没空验证

相关文章: