日期:2014-05-18 浏览次数:21041 次
INSERT TB1 SELECT NID, (SELECT MAX(FNUM) FROM TB1)+ (SELECT COUNT(1) FROM TB2 WHERE NID<=T.NID) AS FNUM ,FDES FROM TB2 T
------解决方案--------------------
declare @a table(id int, fnum int, ftest char(10)) insert into @a select 1, 2, 'aa' union select 21, 3, 'bb' union select 33, 4, 'cc' declare @b table(Nid int, Findex int, fdes char(10)) insert into @b select 11, 12, 'kk' union select 22, 22, 'mm' union select 33, 32, 'ss' insert into @a(id, ftest, fnum) select Nid, fdes, ROW_NUMBER() OVER (order by Findex) + (select MAX(fnum) from @a) from @b as B select * from @a