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

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - Grok.Yao

sqlserver临时启用和关闭约束 string.format 参考 大O表示法 C# 日期格式化参考 查看sql语句的执行时间及缓存执行计划 查看索引执行次数 (转)JQuery有用的50段代码 查询指定日期区间内的每一天 FF和IE兼容的捕获回车事件问题 回车自动提交Form表单的问题 IE下 JS添加Select元素的option问题 VS中的常用快捷键,可以提高开发效率 ashx中使用Session问题 关于CSS控制TD换行与否的问题解决 TFS2008 无法撤销锁定的签出 C#中集合查询的问题! Sql获取随机时间 本地SQL脚本操作外部服务器结果集 RSA容器权限问题
将数据库记录倒为Insert语句的存储过程
Grok.Yao · 2011-06-15 · via 博客园 - Grok.Yao

GO
/****** Object:  StoredProcedure [dbo].[SinaBlog_Album_CreateAlbum]    Script Date: 06/15/2011 17:40:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <grokyao>
-- Create date: <2011-06-15>
-- Description:    <将表中数据倒为Insert语句>
-- =============================================
CREATE   PROCEDURE spGenInsertSQLHan (@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  
 
 
    EXEC (@sql)  
 
END