日期:2014-05-18 浏览次数:20610 次
declare @表TAB table (X int,Y int) insert into @表TAB select 5,null union all select 6,null union all select 8,null union all select 9,null union all select 23,null union all select 15,null /* 有一列数 2 7 9 5 12 32 */ SELECT X,c AS Y FROM (SELECT ROW_NUMBER() OVER ( ORDER BY GETDATE() ) AS id,* FROM @表TAB) a LEFT JOIN (SELECT ROW_NUMBER() OVER ( ORDER BY GETDATE() ) AS id,* FROM (SELECT 2 AS c UNION ALL SELECT 7 UNION ALL SELECT 9 UNION ALL SELECT 5 UNION ALL SELECT 12 UNION ALL SELECT 32) d ) b ON a.id = b.id /* X Y ----------- ----------- 5 2 6 7 8 9 9 5 23 12 15 32 */
------解决方案--------------------
给表加个自增的标识列,新增数据的表也加一个标识列,然后两表按照这个标识列去更新。
update a
set a.y = b.y
from tb1 a join tb2 b on a.id = b.id
------解决方案--------------------