USE [KM_Voice] 

GO 

/****** Object: StoredProcedure [dbo].[proc_insert] Script Date: 01/09/2015 18:44:35 ******/ 

SET ANSI_NULLS ON 

GO 

SET QUOTED_IDENTIFIER ON 

GO 





ALTER proc [dbo].[proc_insert] (@tablename varchar(256)) 







as 







begin 







set nocount on 







declare @sqlstr varchar(4000) 







declare @sqlstr1 varchar(4000) 







declare @sqlstr2 varchar(4000) 







select @sqlstr='select ''insert '+@tablename







select @sqlstr1='' 







select @sqlstr2=' (' 







select @sqlstr1= ' values ( ''+' 







select @sqlstr1=@sqlstr1+col+'+'',''+' ,@sqlstr2=@sqlstr2+name +',' from (select case 







-- when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end' 







when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end' 







when a.xtype =175 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end' 







when a.xtype =61 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end' 







when a.xtype =106 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end' 







when a.xtype =62 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end' 







when a.xtype =56 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(11),'+a.name +')'+' end' 







when a.xtype =60 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end' 







when a.xtype =239 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end' 







when a.xtype =108 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end' 







when a.xtype =231 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end' 







when a.xtype =59 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end' 







when a.xtype =58 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end' 







when a.xtype =52 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(12),'+a.name +')'+' end' 







when a.xtype =122 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end' 







when a.xtype =48 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(6),'+a.name +')'+' end' 





when a.xtype =36 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(36),'+a.name +')'+'+'''''''''+' end' 



-- when a.xtype =165 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end' 







when a.xtype =167 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end' 







else '''NULL''' 







end as col,a.colid,a.name 







from syscolumns a where a.id = object_id(@tablename) and a.xtype <>189 and a.xtype <>34 and a.xtype <>35 --and a.xtype <>36 







)t order by colid 















select @sqlstr=@sqlstr+left(@sqlstr2,len(@sqlstr2)-1)+') '+left(@sqlstr1,len(@sqlstr1)-3)+')'' from '+@tablename







print @sqlstr 







exec( @sqlstr) 







set nocount off 







end  

sqlserver小批量导数据的更多相关文章

  1. sqlserver存储过程批量插入数据

    在系统中经常会遇到向数据库中批量插入数据情况,存储过程中没有数组,只有通过字符串分割循环插入,下面是一个本人研究的一个例子: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 c ...

  2. 利用DataTable快速批量导数据

    DataSet ds = new DataSet();            using (SqlConnection conn = new SqlConnection(@"data sou ...

  3. C#批量插入数据到Sqlserver中的四种方式

    我的新书ASP.NET MVC企业级实战预计明年2月份出版,感谢大家关注! 本篇,我将来讲解一下在Sqlserver中批量插入数据. 先创建一个用来测试的数据库和表,为了让插入数据更快,表中主键采用的 ...

  4. C#批量插入数据到Sqlserver中的三种方式

    本篇,我将来讲解一下在Sqlserver中批量插入数据. 先创建一个用来测试的数据库和表,为了让插入数据更快,表中主键采用的是GUID,表中没有创建任何索引.GUID必然是比自增长要快的,因为你生 成 ...

  5. 【转载】C#批量插入数据到Sqlserver中的三种方式

    引用:https://m.jb51.net/show/99543 这篇文章主要为大家详细介绍了C#批量插入数据到Sqlserver中的三种方式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 本篇, ...

  6. sqlserver 中批量删除\r\n 换行符

    从Excel中向sqlserver 中批量粘贴数据时 可能会粘贴进去换行符 \r\n  这时候在查询时候是看不见的 只有把该字段赋值到‘’中才能发现换行. 批量替换语句: update [表名]set ...

  7. SQLServer使用表值参数,高性能批量插入数据

    记得前段时间帮同事写了个解析账号并入库的小工具,来批量导入账号信息,账号量相当大,程序每读取一条记录便执行一次insert来插入数据,整整跑了一下午才把账号全部入库. 今天又接到同事类似的需求,不过这 ...

  8. SqlServer 利用游标批量更新数据

    SqlServer 利用游标批量更新数据 Intro 游标在有时候会很有用,在更新一部分不多的数据时,可以很方便的更新数据,不需要再写一个小工具来做了,直接写 SQL 就可以了 Sample 下面来看 ...

  9. 自由导入你的增量数据-根据条件将sqlserver表批量生成INSERT语句的存储过程实施笔记

    文章标题: 自由导入你的增量数据-根据条件将sqlserver表批量生成INSERT语句的存储过程增强版 关键字 : mssql-scripter,SQL Server 文章分类: 技术分享 创建时间 ...

随机推荐

  1. SQL Sever 学习系列之三

    SQL Sever 学习系列之三 SQL Server 学习系列之一(薪酬方案+基础) SQL Server 学习系列之二(日期格式问题)         五.经理今天刚谈到with的用法(with的 ...

  2. maven打包指定main函数的入口,生成依赖的包

    为了使Jar包中指定Main方法位置和生成依赖包,需要在pom文件中加入如下配置: <build> <plugins> <plugin> <groupId&g ...

  3. 分治思想的应用:C++实现快速排序和随机化的快速排序

    分治思想的应用:C++实现快速排序和随机化的快速排序 原创 2014年09月08日 14:04:49 标签: 快速排序 / 随机化快速排序 / 排序算法 / 数据结构 947 1. 快速排序时冒泡排序 ...

  4. 杂项-IIS:发布杂项

    ylbtech-杂项-IIS:发布杂项 1. 测试连接返回顶部 1.1.授权 无法验证对路径的访问. 1.2.详情信息 服务器配置为将传递身份验证和内置帐户一起使用,以访问指定的物理路径.但是,IIS ...

  5. mysql查询最近30天、7天、每天、昨天、上个月的记录

      一些变量说明: add_time为插入的时间 to_days是sql函数,返回的是个天数 data_sub(date,INTERVAL expr type)给指定的日期减去多少天 data()函数 ...

  6. windows中git输错密码后不能重新输入的问题

    当输入密码错误后,git会把密码保存在windows的你的当前用户名的缓存中. 我们可以在控制面板中寻找到这个缓存,再删掉就可以了. 首先,打开“控制面板”,把“查看方式”改为“大图标”,再打开“用户 ...

  7. xcopy 命令行

    https://www.cnblogs.com/yang-hao/p/6003308.html xcopy-参数详解   XCOPY——目录复制命令  1.功能:复制指定的目录和目录下的所有文件连同目 ...

  8. springmvc 处理器方法返回的是modelandview 重定向到页面

  9. 手动编译安装tmux

    tmux的好处就不多说了,总之是多屏管理的神器.通常我们用系统通用的安装方式可以安装到tmux,但有时候,安装到的可能不是我们所需要的版本,又或者软件源里面没有带tmux.这个时候就需要手动编译安装了 ...

  10. ElasticSearch入门一

    ElasticSearch入门一 1 安装ElasticSearch,配置环境变量,并且存在Java环境,而且是Java环境: 下图是安装的目录: 进入bin目录之后,请看bin目录: 启动elast ...