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