22,209
社区成员
发帖
与我相关
我的任务
分享
Create table #tabl
(
Id int,
Amount float,
PId int
)
insert into #tabl values(1,100,null)
insert into #tabl values(2,200,null)
insert into #tabl values(3,null,1)
insert into #tabl values(4,null,2)
update b set Amount=a.Amount
from #tabl a
,#tabl b
where a.Id=b.PId
and b.Amount is null
select * from #tabl
drop table #tabl
Create table #tabl
(
Id int,
Amount float,
PId int
)
insert into #tabl values(1,100,null)
insert into #tabl values(2,200,null)
insert into #tabl values(3,null,1)
insert into #tabl values(4,null,2)
update #tabl set Amount=a.Amount
from #tabl a
where a.Id=PId
and Amount is null
update b set Amount=a.Amount
from #tabl a
,#tabl b
where a.Id=b.PId
and b.Amount is null
select * from #tabl
drop table #tabl
/*
Id Amount PId
----------- ---------------------- -----------
1 100 NULL
2 200 NULL
3 100 1
4 200 2
(4 行受影响)
*/