有表 A
id num
1 a
<null> b
<null> c
3 a
<null> c
4 d
<null> c
<null> f請問如何能夠把為空的部分賦值為上一條紀錄顯示的內容
結果如下
id num
1 a
1 b
1 c
3 a
3 c
4 d
4 c
4 f
id num
1 a
<null> b
<null> c
3 a
<null> c
4 d
<null> c
<null> f請問如何能夠把為空的部分賦值為上一條紀錄顯示的內容
結果如下
id num
1 a
1 b
1 c
3 a
3 c
4 d
4 c
4 f
一个UPDATE SQL语句(源自:CSDN lsqkeke(可可)回帖 )
select * into #t1 from
(
select '一' as zd1,'aa' as zd2
union all
select '','bb'
union all
select '','cc'
union all
select '','dd'
union all
select '二','dd'
union all
select '','ee'
union all
select '','ff'
union all
select '','gg'
union all
select '','hh'
union all
select '','ii'
union all
select '','jj'
) aselect * from #t1
declare @zd1 varchar(5)
update #t1
set @zd1=case when zd1<>'' then zd1 else @zd1 end,
zd1=case when zd1='' then @zd1 else zd1 end
select * from #t1
drop table #t1
select null,'b' union all
select null,'c' union all
select 3 , 'a' union all
select null ,'c' union all
select 4 , 'd' union all
select null ,'c' union all
select null , 'f'declare @i int
select @i=id from @ta
update @Ta
set @i=case when id is null then @i else id end,
id=@iselect * from @ta
lsqkeke(可可) 老大脚本少了些东西declare @Ta table (id int,num varchar(10))
insert into @Ta (id,num)
.....