继续昨天单表操作的问题
CREATE TABLE #Ac(uid int IDENTITY, a varchar(5),b varchar(6),c varchar(6))昨天我写的是只更新一列,而实际我上有很多列需要更新,有10多列,又不知道怎么处理!
INSERT INTO #Ac (a,b,c)
select 'A158','100','AAAA' UNION ALL
select '','','AABBA' UNION ALL
select '','','AAXA' UNION ALL
select '','','AACA' UNION ALL
select 'A159','200','AAAA' UNION ALL
select '','','AABBA' UNION ALL
select '','','AAXA' UNION ALL
select '','','AACA' UNION ALL
select 'A168','150','AAAA' UNION ALL
select '','','AABBA' UNION ALL
select '','','AAXA' UNION ALL
select '','','AACA' UNION ALL
select 'A178','345','AAAA'
select uid,
a=(select case when a='' then (select MAX(a) from #ac where a.uid>uid) else a end),
b=(select case when b='' then (select MAX(b) from #ac where a.uid>uid) else b end),
c from #ac a
,a=(select max(a) from #Ac b where a.uid>b.uid)
,b=(select max(b) from #Ac b where a.uid>b.uid)
from #Ac a
where a='' and b=''
group by uid
) t2
on t1.uid=t2.uid
select *
from #Ac