根据表中数据生成insert语句的存储过程
时间:2008-11-10 12:13:00
昨时要导一些数据,从网上搜到的。字段多时insert 语句生成的不完整了,还没有找到原因..
有个缺点……就是标识种子的列 也insert了
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,存储过程,数据,
0
投稿
猜你喜欢
重温Javascript继承机制
2011-07-04 12:17:23
爱你就要说出来,来表白吧
2008-11-23 16:23:00
mysql分表的3种方法
2011-01-29 16:50:00
选项卡动态增删的效果(内嵌框架)
2008-05-22 12:59:00
FSO中的SubFolders 属性介绍
2008-01-05 13:57:00
自适应css布局——流动布局新时代[译]
2009-08-13 12:28:00
简单的在线调试服务端js代码的asp源码
2008-04-23 13:30:00
SQL中exists的使用方法
2011-12-01 08:36:07
防盗链接ASP函数
2011-03-07 11:02:00
IE下绝对定位的元素不能响应鼠标的bug修正
2008-09-10 13:03:00
教你轻松掌握如何正确的修复Access数据库
2008-11-28 16:21:00
基于生活形态的用户分群研究
2009-12-30 16:54:00
MySQL数据库常见的出错代码及出错信息
2008-05-27 12:29:00
asp随机提取access数据库记录的几种方法
2007-09-06 19:42:00
asp可设置参数的分页代码例子
2007-10-07 12:34:00
MySql循环插入数据
2010-10-14 13:50:00
ASP实例:幻灯片新闻代码
2008-11-21 17:40:00
详解php如何合并身份证正反面图片为一张图片
2023-05-22 10:44:46
MySQL中两种快速创建空表的方式的区别
2008-12-17 14:34:00
ASP运行在IIS6 500错误解决办法
2011-04-19 11:15:00