sqlserver 批量增添和修改语句用select

sqlserver 批量添加和修改语句用select

修改语句:

begin
			update PRODUCE_TASKSDETAIL set gcount=a.gcount+
                           case c.STANDBATCH
                            when '0' then @unitCount*b.STANDBATCH
                            else @unitCount/c.STANDBATCH*b.STANDBATCH
                           end
            from PRODUCE_TASKSDETAIL as a,PRODUCE_BOM_SUB as b,PRODUCE_BOM_BOM as c
            where a.goodsid=b.goodsid and b.BOMID=c.BOMID and c.GOODSID=@goodsId and a.tasksid=@tasksId
         end

 添加语句:

begin 
   insert into PRODUCE_TASKSDETAIL(SALEORDER_BILLCODE,TASKSID,GOODSID,UNITID,goodsCount,GCOUNT,GPRICE) 
                  select @billCode,@tasksId,a.GOODSID,a.UNITID,a.STANDBATCH,
                           case c.STANDBATCH
                            when '0' then @unitCount*a.STANDBATCH
                            else @unitCount/c.STANDBATCH*a.STANDBATCH
                           end
                          ,b.APRICE from PRODUCE_BOM_SUB as a,BASE_GOODS as b,PRODUCE_BOM_BOM as c
                   where a.GOODSID=b.GOODSID and a.BOMID=c.BOMID and a.BOMID in(select BOMID from PRODUCE_BOM_BOM where GOODSID=@goodsId) 
		end