dbcc inputbuffer(@@spid)
我知道这个可以
可是他的eventinfo的返回值才255个字符
而我的sql有几千个字符呢~select *  from inserted获得是一个记录集
而我想要的只是这个将要执行的insert语句
一个字段一个字段取再合并,太慢,通用性又不好敢问大家,有什么好的方法吗?
谢谢指教~````

解决方案 »

  1.   

    我也关心这个问题,insert,update都关心
      

  2.   

    根据表中数据生成insert语句的存储过程 declare @tablename varchar(100)
    set @tablename = 'da_k' 
    declare @sql varchar(8000)  declare @sqlvalues varchar(8000)  set @sql ='('  set @sqlvalues = 'values(''+'  select @sqlvalues = @sqlvalues + cols + ' + '','' + ' ,@sql = @sql + '' + name + ','     from         (select case                   when xtype in (48,52,56,59,60,62,104,106,108,122,127)                                                       then 'case when '+ name +' is null then ''NULL'' else ' + 'cast('+ name + ' as varchar)'+' end'                  when xtype in (58,61)                       then 'case when '+ name +' is null then ''NULL'' else '+''''''''' + ' + 'cast('+ name +' as varchar)'+ '+'''''''''+' end'                 when xtype in (167)                       then 'case when '+ name +' is null then ''NULL'' else '+''''''''' + ' + 'replace('+ name+','''''''','''''''''''')' + '+'''''''''+' end'                  when xtype in (231)                       then 'case when '+ name +' is null then ''NULL'' else '+'''N'''''' + ' + 'replace('+ name+','''''''','''''''''''')' + '+'''''''''+' end'                  when xtype in (175)                       then 'case when '+ name +' is null then ''NULL'' else '+''''''''' + ' + 'cast(replace('+ name+','''''''','''''''''''') as Char(' + cast(length as varchar)  + '))+'''''''''+' end'                  when xtype in (239)                       then 'case when '+ name +' is null then ''NULL'' else '+'''N'''''' + ' + 'cast(replace('+ name+','''''''','''''''''''') as Char(' + cast(length as varchar)  + '))+'''''''''+' end'                  else '''NULL'''                end as Cols,name           from syscolumns            where id = object_id(@tablename)         ) T   set @sql ='select ''INSERT INTO '+ @tablename + ' ' + left(@sqlvalues,len(@sqlvalues)-4) + ')'' from '+@tablename
      --set @sql ='select ''INSERT INTO '+ @tablename + ' ' + left(@sqlvalues,len(@sqlvalues)-4) + ')'' from '+@tablename
      print @sql
    exec (@sql)
    可以改造 成存储过程
      

  3.   

    Thank You~~~~~``
    我先理解一下~~
      

  4.   

    看来如果没有简便的方法我还是在程序里写吧~~毕竟,还有update和delete结帖````````