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

推荐订阅源

WordPress大学
WordPress大学
Spread Privacy
Spread Privacy
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy & Cybersecurity Law Blog
L
LINUX DO - 热门话题
T
Threat Research - Cisco Blogs
T
Tenable Blog
TaoSecurity Blog
TaoSecurity Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
AI
AI
P
Proofpoint News Feed
A
About on SuperTechFans
P
Privacy International News Feed
月光博客
月光博客
雷峰网
雷峰网
S
Secure Thoughts
博客园 - 叶小钗
博客园 - 聂微东
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Project Zero
Project Zero
The Cloudflare Blog
SecWiki News
SecWiki News
The Hacker News
The Hacker News
V
Vulnerabilities – Threatpost
罗磊的独立博客
A
Arctic Wolf
阮一峰的网络日志
阮一峰的网络日志
Know Your Adversary
Know Your Adversary
酷 壳 – CoolShell
酷 壳 – CoolShell
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Troy Hunt's Blog
The Last Watchdog
The Last Watchdog
Schneier on Security
Schneier on Security
小众软件
小众软件
有赞技术团队
有赞技术团队
博客园 - 司徒正美
T
Tailwind CSS Blog
量子位
C
Cybersecurity and Infrastructure Security Agency CISA
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Security @ Cisco Blogs
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
L
Lohrmann on Cybersecurity

博客园 - 冷风.net

以OO的思想利用JS來實現五子棋 開放幾個原來寫的js代碼,供大家娛樂一下 使用JS寫的第一個游戲[俄羅斯方塊] 假如現在讓你去說服客戶使用asp.net2.0開發系統,你會怎麼說服呢? 對象化javascript日期控件 - 冷风.net - 博客园 工作排程 防止圖片在WEB頁面上下載 - 冷风.net - 博客园 今天從新整理的大小寫數據轉換 - 冷风.net - 博客园 常用的XPATH說明 XmlHttp在DoNet中的完全应用---前/后台完成分离篇 系统用户权限与角色分析 学习设计模式之Composite 模式 改進Richer的WEB頁面進度條! 学习设计模式之Bridge模式 学习设计模式之生成器(Builder Pattern)模式 再谈Abstract Factory模式来实现数据库操作的类 Factory Method来实现数据库操作的类 今天下午困惑的問題,終於TMD搞出來了 利用線程實現錠時執行的運行模型
不周表結構合併問題
冷风.net · 2005-02-24 · via 博客园 - 冷风.net

幾次遇到關於兩個無關的表合併問題,因人太懶了,我都不知道如解決的了,
最近又遇到了(原因是同類產品有不同的數據結構表---想想那個設計者我就想日),沒法必須要解決了,終於下定決心了來解決了
如下:

/*********************************************************************************************************************
表一
A     B      C       D     FED1        FED2             FED3        
147    110    141.06    147.88    NULL    1998-12-01 00:00:00.000    122.15
表二
E       F       G      H      I      J      K    FED1        FED2             FED3
146.81    114.38    182.88    143.06    152.31    47.67    63.36    NULL    1999-01-01 00:00:00.000    126.69
合並表:
A    B    C    D        E    F    G    H    I    J    K    FED1    FED2                FED3
147    110    141.06    147.88        0      0    0    0    0    0    0    NULL    1998-12-01 00:00:00.000    122.15
0            0        0                0            146.81    114.38    182.88    143.06    152.31    47.67    63.36    NULL    1999-01-01 00:00:00.000    126.69
*@Function:從表一表二得到合併表(注:表一表二的結構未知)
*@Author: 何利民
*@Create Date:2005-02-24
*@Parameters:@tbName1表一@tbName2表二
********************************************************************************************************************
*/

CREATE PROCEDURE  [dbo].[MergeTable] 
(
@tbName1 
nvarchar(50),
@tbName2 
nvarchar(50)
)
AS
--將要合併的兩個表分並存在臨時表##tmp與##tmp1
declare @sqlStr nvarchar(4000)
set @sqlStr='select * into ##tmp from '+@tbName1+'; select * into ##tmp1 from '+@tbName2
exec(@sqlStr)
declare @tb1 nvarchar(50)
declare @tb2 nvarchar(50)
set @tb1='##tmp'
set @tb2='##tmp1'

--在表一中增加表二中多余的結構
set @sqlStr=''
declare @fed nvarchar(50)
Declare newcursor Cursor local forward_only static read_only type_warning
for select [name] from tempdb.dbo.syscolumns where id=(select id from tempdb.dbo.sysobjects where id=object_id(N'[tempdb].[dbo].['+@tb2+']'))
open newcursor
fetch next from newcursor into @fed
while(@@fetch_status=0)
begin
    
if(not exists(select [name] from tempdb.dbo.syscolumns where id=(select id from tempdb.dbo.sysobjects where id=object_id(N'[tempdb].[dbo].['+@tb1+']')) and name=@fed))
    
begin
        
set @sqlStr=@sqlStr+'Alter table '+@tb1+'  '
        
set @sqlStr=@sqlStr+'add ['+@fed+'] nvarchar(10);'
    
end
    
fetch next from newcursor into @fed
end
exec(@sqlStr)
close newcursor
deallocate newcursor

--在表二中增加表一中多余的結構
set @sqlStr=''
Declare newcursor Cursor local forward_only static read_only type_warning
for select [name] from tempdb.dbo.syscolumns where id=(select id from tempdb.dbo.sysobjects where id=object_id(N'[tempdb].[dbo].['+@tb1+']'))
open newcursor
fetch next from newcursor into @fed
while(@@fetch_status=0)
begin
    
if(not exists(select [name] from tempdb.dbo.syscolumns where id=(select id from tempdb.dbo.sysobjects where id=object_id(N'[tempdb].[dbo].['+@tb2+']')) and name=@fed))
    
begin
        
set @sqlStr=@sqlStr+'Alter table '+@tb2+'  '
        
set @sqlStr=@sqlStr+'add ['+@fed+'] nvarchar(10);'
    
end
    
fetch next from newcursor into @fed
end
exec(@sqlStr)
close newcursor

--對兩表進行合併結果存入臨時表##resultTable
declare @fedStr nvarchar(4000)
set @fedStr=''
select @fedStr=@fedStr+'['+name+'],'  from tempdb.dbo.syscolumns where id=(select id from tempdb.dbo.sysobjects where id=object_id(N'[tempdb].[dbo].['+@tb1+']'))
if(right(@fedStr,1)=',')
    
set @fedStr=left(@fedStr,len(@fedStr)-1)
set @sqlStr='select *  into  ##resultTable  from  (select '+@fedStr+'  from ##tmp union all select '+@fedStr+'  from  ##tmp1) a'
exec(@sqlStr)

drop table ##tmp
drop table ##tmp1
GO