调用存储过程导出sql的数据!
drop proc proc_insert
if exists (select name from sysobjects where
name = 'proc_insert' and type='P')
drop procedure proc_insert
go
create proc 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 =127 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(20),'+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 =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
go
2.然后
调用:
exec proc_insert 't_case_type'
分享到:
相关推荐
NPOI导出SQL数据保存为Exce文件
请看下面的操作图解。 1.使用Sql Server Management Studio 2008 连接数据库。 2.选中要导出数据的数据库节点,点鼠标右键,在菜单中...从SQL SERVER 2008开始,我们就可以很方便的导出数据脚本,而无需再借助存储过
自动判断当前数据库(目前支持SQL2000及以上版本)。将数据库中的数据导出为insert脚本。
vbs从sqlserver数据库导出数据成execl
数据导出工具,可以导出SQL 数据导出工具,可以导出SQL 数据导出工具,可以导出SQL 数据导出工具,可以导出SQL
VC 导出数据库和导出SQL语句程序,一个数据开发小工具源码,并可简单的分析SQL语句语法,前几年的程序了,有兴趣的下载源码研究下。
关于SqlServer通过脚本访问Excel数据,以及通过企业管理器导入Excel数据问题解决办法。
SMImport 组件包能够导入如下文件格式的数据 1. MS Excel spreadsheet (directly without OLE/DDE) 2. text delimited file 3. text fixed width file 4. XML file 5. HTML file 6. MS Access database 7. MS Word ...
此软件可以顺利的将数据库中的所有数据导出成为sql语句,用于数据导入导出是个不错的工具
SQL SERVER数据导出工具SQL SERVER数据导出工具SQL SERVER数据导出工具SQL SERVER数据导出工具SQL SERVER数据导出工具SQL SERVER数据导出工具SQL SERVER数据导出工具
可以选定表、自定义查询,生成Insert语句
生成excel,修改excel字段名,见方法field_name()
怎么定时自动将SQL数据导出为Excel文件
可以将数据库中的数据导出insert into脚本, sql server2008以上版本已经自带导出数据库数据成insert脚本功能,该工具针对2005以下版本.使用时先选择数据库服务器地址,在右侧选择Sql Server login,输入数据库账号...
能方便地导出SqlServer数据库的数据字典,能分别单个或全部地导出表以及视图的数据字典。导出后的数据字典为Excel格式。 注意:使用前必须安装.NET 2.0
可导出SQL数据,同时支持导出表结构,支持SQL Server2000、SQL Server2005
导出sql server表数据(生成以insert插入的语句方式的存储过程)
magento导出数据sql,magento批量导出数据,magento批量上传数据。
一般我们只能导出数据表的机构,不能导出表数据,导出表数据需要自己编写SQL语句,此存储过程就是能够将数据表的内容导出成sql语句
NULL 博文链接:https://cookices.iteye.com/blog/2009447