例如:A表有,字段:ID;Count
1 13
2 5
B表有,字段:BID;BCount
1 5
2 6
现在在存储过程里想判断A表的Count和BCount的大小。这俩字段都没有参数带进来的。
想要实现的效果:
if(Count>BCount)
insert.....
else
update......
1 13
2 5
B表有,字段:BID;BCount
1 5
2 6
现在在存储过程里想判断A表的Count和BCount的大小。这俩字段都没有参数带进来的。
想要实现的效果:
if(Count>BCount)
insert.....
else
update......
--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...
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