SQL中的动态语句执行--exec(@sqlstr)


 1 begin
 2 drop table #tmptable
 3 declare @money ut_money
 4 set @money=1.2345
 5 create table #tmptable
 6 (
 7 je ut_money
 8 )
 9 
10 insert into #tmptable(je) values(@money)
11 
12 select * from   #tmptable
13 
14 end

执行结果:

 

第二段sql

 1 begin
 2 drop table #tmptable
 3 declare @money ut_money
 4 set @money=1.2345
 5 create table #tmptable
 6 (
 7 je ut_money
 8 )
 9 
10 exec('insert into #tmptable(je) values('+@money+')')
11 
12 
13 select convert(varchar(20),@money)
14 select * from   #tmptable
15 
16 end

执行结果:

 

 

以上结果表明:

exec(@sqlstr)

其中@sqlstr中如果包含变量的运算,是将变量转换为varchar后再exec操作


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM