--更新已经有的
update b set point=isnull(b.point,0)+isnull(a.result,0)
from b join(
select userid,result from A表
where postid=某个数值
group by result
)a on a.userid=b.userid--插入不存在的
insert b(userid,point)
select a.*
from(
select userid,result from A表
where postid=某个数值
group by result
)a left join b on a.userid=b.userid
where b.userid is null
--写成处理的存储过程
create proc p_process
@PostID int
as
set xact_abort on
begin tran --用事务处理
--更新已经有的
update b set point=isnull(b.point,0)+isnull(a.result,0)
from b join(
select userid,result from A表
where postid=@PostID
group by result
)a on a.userid=b.userid
--插入不存在的
insert b(userid,point)
select a.*
from(
select userid,result from A表
where postid=@PostID
group by result
)a left join b on a.userid=b.userid
where b.userid is null
commit tran
go
当然没问题.
update b set point=isnull(b.point,0)+isnull(a.result,0)
from b join(
select userid,,result=sum(result) from A表
where postid=某个数值
group by result
)a on a.userid=b.userid--插入不存在的
insert b(userid,point)
select a.*
from(
select userid,result=sum(result) from A表
where postid=某个数值
group by result
)a left join b on a.userid=b.userid
where b.userid is null
--写成处理的存储过程
create proc p_process
@PostID int
as
set xact_abort on
begin tran --用事务处理
--更新已经有的
update b set point=isnull(b.point,0)+isnull(a.result,0)
from b join(
select userid,result=sum(result) from A表
where postid=@PostID
group by result
)a on a.userid=b.userid
--插入不存在的
insert b(userid,point)
select a.*
from(
select userid,result=sum(result) from A表
where postid=@PostID
group by result
)a left join b on a.userid=b.userid
where b.userid is null
commit tran
go