惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
N
News and Events Feed by Topic
P
Privacy International News Feed
The Hacker News
The Hacker News
Schneier on Security
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
Security Latest
Security Latest
L
LINUX DO - 最新话题
阮一峰的网络日志
阮一峰的网络日志
Cisco Talos Blog
Cisco Talos Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
博客园 - 【当耐特】
博客园 - Franky
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
月光博客
月光博客
D
Docker
Webroot Blog
Webroot Blog
The GitHub Blog
The GitHub Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
S
Security Affairs
Martin Fowler
Martin Fowler
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
Microsoft Azure Blog
Microsoft Azure Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
Lohrmann on Cybersecurity
T
Threatpost
量子位
S
Schneier on Security
V
Visual Studio Blog
S
Securelist
T
The Exploit Database - CXSecurity.com
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
I
Intezer
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
小众软件
小众软件
罗磊的独立博客
雷峰网
雷峰网
Recorded Future
Recorded Future

博客园 - RedFox(低调)

多大的船决定要承担多大的阻力,多大的风浪会炼出多厉害的船长,大副,二副,水手。。。。很多时候不是你选择了风浪,而是风浪选择并决定了你!优秀的水手觉得不是战胜了风浪,而是适应了风浪。 jdk国内镜像 基于vue-cli的vs code设置 maven 国内完整源 怎么看待MYSQL的性能 java dom4j 读写XML cas4.2的安装 java websocket 解决openresty http客户端不支持https的问题 开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别 为何Google这类巨头会认为敏捷开发原则是废话? git ldap 获取大众点评数据 svn for vs 色彩设计,是产品设计,营销渠道的一个重要环节 sql xml 腾讯或正在陷入全面危机? 项目实施与管理的几点建议 ERP与进销存软件的区别
SQL 导出表数据存储过程
RedFox(低调) · 2013-09-17 · via 博客园 - RedFox(低调)
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- ============================================= 
-- Author: 
-- Create date:
-- Description: 将表数据生成Insert脚本 
-- Demo : exec pCreateInsertScript 'TestTable','1=1' 
-- ============================================= 
CREATE PROC [dbo].[pCreateInsertScript] (
	@tablename VARCHAR(256)
	,@con NVARCHAR(400)
	)
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 = 127
					THEN 'case when ' + a.NAME + ' is null then ''NULL'' else ' + 'convert(varchar(6),' + 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 + ' where 1=1 and ' + isnull(@con, '')

	PRINT @sqlstr

	EXEC (@sqlstr)

	SET NOCOUNT OFF
END
GO