• 根据表中数据生成insert语句的存储过程


    View Code
    create   proc spgeninsertsql (@tablename varchar(256))
    as
    begin
    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(@sql,len(@sql)-1)+) + left(@sqlvalues,len(@sqlvalues)-4) + ) from +@tablename
    --print @sql
    exec (@sql)
    end
    go
    千人.NET交流群:18362376,因为有你,代码变得更简单,加群请输入cnblogs
  • 相关阅读:
    storcli64 查看raid
    初学者路径规划 | 人生苦短我用Python
    Vue.js组件的重要选项
    三个Bootstrap免费字体和图标库
    前端实时消息提示的效果-websocket长轮询
    前端实时消息提示的效果-websocket长轮询
    带分页的标签
    带分页的标签
    VMware-workstation安装
    VMware-workstation安装
  • 原文地址:https://www.cnblogs.com/kingkoo/p/2383172.html
Copyright © 2020-2023  润新知