分两步走,无须存储过程.
update ... from a , b where a.id = b.bid and a.Count <= b.bcount
insert into ... select ... from a , b where a.id = b.bid and a.Count > b.bcount
--问题是,两个表中各有多条记录,它们有大有小,你以什么来比较呢?
--ID 相同的进行比较是一个选择,那必须要有个ID:
if exists(select 1 from A inner join B on a.id=b.id where a.id=@id and a.Count>b.Bcount)
insert ....
else
update...