(转)根据表中数据生成insert语句的存储过程
来源:互联网 发布:4g数据流量费什么意思 编辑:程序博客网 时间:2024/05/16 17:33
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
- 根据表中数据生成insert语句的存储过程
- 根据表中数据生成insert语句的存储过程
- 根据表中数据生成insert语句的存储过程
- 根据表中数据生成insert语句的存储过程
- (转)根据表中数据生成insert语句的存储过程(另一种方法)
- (转)根据表中数据生成insert语句的存储过程
- SQLSERVER表数据生成INSERT语句(通用存储过程)
- 生成insert语句的存储过程
- 生成表insert into语句的存储过程
- 将表中的数据生成Insert脚本的存储过程!!!
- 一个把表中数据生成Insert脚本的通用存储过程
- mssql 生成‘批量Insert数据的sql语句’的存储过程
- 自动生成INSERT语句的SQL存储过程
- 将数据库表中的数据生成Insert脚本的存储过程(改版)
- 生成Insert语句SQL存储过程
- SQL Server 存储过程生成insert语句
- 根据基本表结构及其数据生成INSERT 语句的SQL脚本
- 导出数据库数据记录成insert语句的存储过程
- 自己重新整理攒一个 SqlHelper.v3.1.cs 备用! (纯属抄袭)
- Java Tip 96: 使用 HTTPS 编写客户端程序
- pb中使用winapi生成全球唯一标示码(GUID,UUID)
- [转]自己动手打造嵌入式Linux软硬件开发环境
- .Net/C#: 一个将在线简体中文网页转为繁体中文页简单方法 (尚不完善 IHttpHandler Proxy / Response.Filter)
- (转)根据表中数据生成insert语句的存储过程
- 关于委托
- 【转贴】中国人可以活得更好
- 一个用c#写的扫描asp源码漏洞的应用程序(续)
- 让你的delphi程序支持外部参数
- c#.net常用函数和方法集(转)
- 用asp.net还原与恢复sqlserver数据库(转)
- 一个拷贝整个文件夹(包括子文件夹)的方法
- 手工创建显示主窗体