首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求一更新的存储过程,该怎么处理

2012-01-12 
求一更新的存储过程A表有字段:bm,num,storage,lxB表有字段:bm,num,storage现在要根据A表中lx1的记录查询

求一更新的存储过程
A表有字段:
bm,num,storage,lx

B表有字段:
bm,num,storage

现在要根据A表中lx=1的记录查询出来,如果B表中bm和storage相等(即有同库同品种)的就更新B表对应记录的数量num

B没有找到同库同品种的就插入新的记录

[解决办法]
update b set num=aa.num from (select bm,num,storage from a where lx=1) aa where aa.bm=b.bm and aa.storage=b.storage

insert b select a.bm,a.num,a.storage from a left join b on a.bm=b.bm and a.storage=b.stroage where lx=1 and b.bm is null

热点排行