首页 新闻 赞助 找找看

sql中获取exec执行的值

0
悬赏园豆:5 [已解决问题] 解决于 2014-12-23 09:35
declare @sql nvarchar(1000)
set @sql='select getdate()'

declare @tt nvarchar(50)
exec sp_executesql @sql,@tt output

select @tt

查询中,怎样获取到字符脚本的执行结果,如:@sql

sql
凡一二三的主页 凡一二三 | 初学一级 | 园豆:85
提问于:2014-12-22 17:37
< >
分享
最佳答案
0

既然参数@tt可以返回,为什么不再定义个参数用于@sql输出:@OutSQL output

收获园豆:5
大志若愚 | 老鸟四级 |园豆:2138 | 2014-12-22 18:35
其他回答(2)
0

print(@sql)

问天何必 | 园豆:3311 (老鸟四级) | 2014-12-22 17:44
0
DECLARE @temp TABLE
    (
      Id INT,
      Title nvarchar(50),
      Value    nvarchar(1000),
      Remark nvarchar(1000),
      Pass nvarchar(50)
    )  

   --获取自增最大值
   declare @flag int
   select @flag=Isnull(MAX(Id),0) from  AkWorkOrderPrintDate
   
   --变量
   while @flag>0
   begin
      --是否存在这条记录
      declare @count int
      select @count=COUNT(*) from AkWorkOrderPrintDate where Id=@flag
      if @count=1
      begin
        --拷贝这行的数据
        insert into @temp 
        select Id,Title,Value,Remark,'值错误' from AkWorkOrderPrintDate where Id=@flag
        
        --测试日期设置
        declare @val nvarchar(1000)
        select @val=Value from @temp where Id=@flag
        set @val='select @a='+@val
        
        --执行
        begin try
          declare @pass nvarchar(1000)
          exec sp_executesql @val,N'@a int output',@pass output 
  
          update @temp set Pass=@pass where Id=@flag
        end try
        begin catch
        end catch
      end
      set @flag=@flag-1
   end
   
   select * from @temp
凡一二三 | 园豆:85 (初学一级) | 2014-12-23 09:32

支持(0) 反对(0) 凡一二三 | 园豆:85 (初学一级) | 2014-12-23 09:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册