日期:2014-05-17 浏览次数:20384 次
CREATE TABLE #AA(uid int IDENTITY, a varchar(5),b varchar(6))
INSERT INTO #AA (a,b)
select 'A158','AAAA' UNION ALL
select '','AABBA' UNION ALL
select '','AAXA' UNION ALL
select '','AACA' UNION ALL
select 'A159','AAAA' UNION ALL
select '','AABBA' UNION ALL
select '','AAXA' UNION ALL
select '','AACA' UNION ALL
select 'A168','AAAA' UNION ALL
select '','AABBA' UNION ALL
select '','AAXA' UNION ALL
select '','AACA' UNION ALL
select 'A178','AAAA'
CREATE TABLE #AA(uid int IDENTITY, a varchar(5),b varchar(6))
INSERT INTO #AA (a,b)
select 'A158','AAAA' UNION ALL
select '','AABBA' UNION ALL
select '','AAXA' UNION ALL
select '','AACA' UNION ALL
select 'A159','AAAA' UNION ALL
select '','AABBA' UNION ALL
select '','AAXA' UNION ALL
select '','AACA' UNION ALL
select 'A168','AAAA' UNION ALL
select '','AABBA' UNION ALL
select '','AAXA' UNION ALL
select '','AACA' UNION ALL
select 'A178','AAAA'
select * from #AA
update t1
set a=(select top 1 a from #AA t2 where t2.uid<=t1.uid and t2.a<>'' order by a desc)
from #AA t1
select * from #AA
drop table #AA
/*
1 A158 AAAA
2 A158 AABBA
3 A158 AAXA
4 A158 AACA
5 A159 AAAA
6 A159 AABBA
7 A159 AAXA
8 A159 AACA
9 A168 AAAA
10 A168 AABBA
11 A168 AAXA
12 A168 AACA
13 A178 AAAA
*/