未完待续..................... --1.生成动作说明 if @tempchangeTBID='' begin SET @delSPid=replace(@delSPid,',',''',''') exec ('DECLARE my_cursor_sp CURSOR FOR SELECT namec,medicinemodel,outlookc,unitc,productnm,nsaler_product.memo2,nsaler_product.jkycj FROM product,nsaler_product where product.productid=nsaler_product.productid and nsaler_product.salerproductid in ('''+@delSPid+'''))') end else begin SET @tempchangeTBID=replace(@changeTBID,',',''',''') exec ('DECLARE my_cursor_sp CURSOR FOR SELECT namec,medicinemodel,outlookc,unitc,productnm,nsaler_product.memo2,nsaler_product.jkycj FROM product,nsaler_product where product.productid=nsaler_product.productid and exists(select salerproductid from project_saler_product where project_saler_product.salerproductid=nsaler_product.salerproductid and [id] in ('''+@tempchangeTBID+'''))') end
OPEN my_cursor_sp
FETCH NEXT FROM my_cursor_sp into @namec,@medicinemodel,@outlookc,@unitc,@productnm,@memo2,@jkycj
WHILE @@FETCH_STATUS = 0 BEGIN set @index=@index+1 set @actionDesc=@actionDesc+' 产品'+convert(varchar(10),@index)+':'+@namec+' || '+@medicinemodel+' || '+@outlookc+' || '+@unitc+ ' || '+isnull(@productnm,'无')+' || '+convert(varchar(10),@memo2)+' || '+@jkycj FETCH NEXT FROM my_cursor_sp into @namec,@medicinemodel,@outlookc,@unitc,@productnm,@memo2,@jkycj END
CLOSE my_cursor_sp DEALLOCATE my_cursor_sp
select @actionDesc=@actionDesc+' 替换为: '+namec+' || '+medicinemodel+' || '+outlookc+' || '+unitc + ' || '+isnull(nsaler_product.productnm,'无')+' || '+convert(varchar(10),nsaler_product.memo2)+' || '+nsaler_product.jkycj, @standMemo2=nsaler_product.memo2 from product,nsaler_product where product.productid=nsaler_product.productid and nsaler_product.salerproductid=@standardSPid select @cnn=@@rowcount,@err=@err+@@error
begin tran
--2.记录整合的动作说明 insert into unit_action (eventid,unitetype,actiondesc,actdate,operatorid) values(@eventid,'商品整合',@actionDesc,getdate(),@operatorid) select @cnn=@@rowcount,@err=@err+@@error
--3.记录动作明细 if @changeTBID <>'' begin --3.1 替换nsaler_product表的productid set @changePriceTBID=@changePriceTBID+',' set @changeTBID=@changeTBID+',' set @changeMemo2=@changeMemo2+',' set @Changeprice1=@Changeprice1+',' set @Changebidprice=@Changebidprice+','
while @changeTBid_cur <LEN(LTRIM(RTRIM(@changeTBID))) begin --需整合的商品的ID SET @changeTBid_cur=CHARINDEX(',',@changeTBID,@changeTBid_pre) SET @tempTBid=SUBSTRING(@changeTBID,@changeTBid_pre,@changeTBid_cur-@changeTBid_pre) SET @changeTBid_pre=@changeTBid_cur+1
--是否需要调整价格 0 不调整 1 调整 SET @changePriceTBid_cur=CHARINDEX(',',@changePriceTBID,@changePriceTBid_pre) SET @tempchangePriceTBID=SUBSTRING(@changePriceTBID,@changePriceTBid_pre,@changePriceTBid_cur-@changePriceTBid_pre) SET @changePriceTBid_pre=@changePriceTBid_cur+1
--需整合商品的转换系数 SET @changeMemo2_cur=CHARINDEX(',',@changeMemo2,@changeMemo2_pre) SET @tempChangeMemo2=SUBSTRING(@changeMemo2,@changeMemo2_pre,@changeMemo2_cur-@changeMemo2_pre) SET @changeMemo2_pre=@changeMemo2_cur+1
--需整合商品的开标价 SET @changePrice1_cur=CHARINDEX(',',@Changeprice1,@changePrice1_pre) SET @tempChangeprice1=SUBSTRING(@Changeprice1,@changePrice1_pre,@changePrice1_cur-@changePrice1_pre) SET @changePrice1_pre=@changePrice1_cur+1
--需整合商品的中标价 SET @changeBidprice_cur=CHARINDEX(',',@Changebidprice,@changeBidprice_pre) SET @tempChangebidprice=SUBSTRING(@Changebidprice,@changeBidprice_pre,@changeBidprice_cur-@changeBidprice_pre) SET @changeBidprice_pre=@changeBidprice_cur+1
if @tempchangePriceTBID='1' begin set @strbidprice=@tempChangebidprice+'/'+@tempChangeMemo2+'*'+convert(varchar,@standMemo2) set @strprice1=@tempChangeprice1+'/'+@tempChangeMemo2+'*'+convert(varchar,@standMemo2)
select @sqltext='update project_saler_product set bidprice=convert(numeric(20,4),'+@strbidprice+'),price1=convert(numeric(20,4),'+@strprice1+'), salerproductid='''+@standardSPid+''' where [id]='''+@tempTBid+'''' end else begin select @sqltext='update project_saler_product set salerproductid='''+@standardSPid+''' where [id]='''+@tempTBid+'''' end
insert into unit_action_detail (detailid,eventid,sqltype,sqltext,whichtable,previouskey,presentkey) values(@detailid,@eventid,'1',@sqltext,'project_saler_product',@tempTBid,@tempTBid) select @cnn=@@rowcount,@err=@err+@@error --替换前先备份到副本表 insert into project_saler_product_copyright (detailid,[ID],ProjectId,SalerProductId,SalerId,Price, Price1,IsYijia,YijiaPrice1,YijiaPrice2,IsBid,BidPrice,TempLsPrice,LsPrice,Pack, Cengci,ZhiCai,SalerName,Score,Vote,Memo1,Memo2,Memo3,Memo4,Memo5) select @detailid,[ID],ProjectId,SalerProductId,SalerId,Price, Price1,IsYijia,YijiaPrice1,YijiaPrice2,IsBid,BidPrice,TempLsPrice,LsPrice,Pack, Cengci,ZhiCai,SalerName,Score,Vote,Memo1,Memo2,Memo3,Memo4,Memo5 from project_saler_product where [id]=@tempTBid select @cnn=@@rowcount,@err=@err+@@error
--开始替换 if @tempchangePriceTBID='1' begin update project_saler_product set salerproductid=@standardSPid, bidprice=convert(numeric(20,4),bidprice/convert(int,@tempChangeMemo2)*@standMemo2), price1=convert(numeric(20,4),price1/convert(int,@tempChangeMemo2)*@standMemo2) where [id]=@tempTBid select @cnn=@@rowcount,@err=@err+@@error end else begin update project_saler_product set salerproductid=@standardSPid where [id]=@tempTBid select @cnn=@@rowcount,@err=@err+@@error end if @err>0 begin break end end end
begin set @delSPid=@delSPid+',' while @delSPid_cur <LEN(LTRIM(RTRIM(@delSPid))) begin SET @delSPid_cur=CHARINDEX(',',@delSPid,@delSPid_pre) SET @tempSPid=SUBSTRING(@delSPid,@delSPid_pre,@delSPid_cur-@delSPid_pre) SET @delSPid_pre=@delSPid_cur+1
select @detailid=newid() --3.2.1记录删除动作明细 sqltype:整合的sql语句类型0--delete , 1--update, 2--insert select @sqltext='delete from nsaler_product where salerproductid='''+@tempSPid+'''' insert into unit_action_detail (detailid,eventid,sqltype,sqltext,whichtable,previouskey,presentkey) values(@detailid,@eventid,'0',@sqltext,'nsaler_product',@tempSPid,@standardSPid) select @cnn=@@rowcount,@err=@err+@@error --3.2.2删除前先备份 insert into nsaler_product_copyright (detailid,OperatorId,SalerProductId,ProductId,ProductNm,ProductNmE,Lxpj,Isxyzs,Xyzs,pzwh,Xyzsvalidity, isXypc,Xypcpzwh,isscpj,yScpj,zsscpj,isFzyp,Fzypwh,Yppzzs,Zlpz,Isyqbg,Yqbgbh,Yqbgvalidity,Iszlbhy, Zlh,Zlhvalidity,Isgmp,Gmpbh,Gmpfw,gmptime,Gmpvalidity,Isgmpqy,Ylzm,Ylzmqy,Ylzmh,Ylzmvalidity, Isgyzm,Gyzmurl,Iscmsb,Isgxcp,Gxcpph,Gxcpvalidity,Isyyy,PicUrl,Pack,Fgmpprice,Gmpprice,Wsprice,Hsprice, wspprice,Hspprice,Lsprice,Validity,Actiontime,Issczm,SczmValidity,Bwtqyid,Iszmwj,Qyid,Zmwjurl,Isfrzm, Bsqrxm,Bsqrsfz,Bsqryxq,Bsqwjurl,Status,Flag,Issalerid,Issbzcz,Fzsj,Isjky,Jkycj,Jkydlid,Isxy,XyValidity, Memo,Isyphf,issb,Isjkzcz,Isjkjybg,memo1,memo2,memo3,memo4,memo5,PzDate) select @detailid,OperatorId,SalerProductId,ProductId,ProductNm,ProductNmE,Lxpj,Isxyzs,Xyzs,pzwh,Xyzsvalidity, isXypc,Xypcpzwh,isscpj,yScpj,zsscpj,isFzyp,Fzypwh,Yppzzs,Zlpz,Isyqbg,Yqbgbh,Yqbgvalidity,Iszlbhy, Zlh,Zlhvalidity,Isgmp,Gmpbh,Gmpfw,gmptime,Gmpvalidity,Isgmpqy,Ylzm,Ylzmqy,Ylzmh,Ylzmvalidity, Isgyzm,Gyzmurl,Iscmsb,Isgxcp,Gxcpph,Gxcpvalidity,Isyyy,PicUrl,Pack,Fgmpprice,Gmpprice,Wsprice,Hsprice, wspprice,Hspprice,Lsprice,Validity,Actiontime,Issczm,SczmValidity,Bwtqyid,Iszmwj,Qyid,Zmwjurl,Isfrzm, Bsqrxm,Bsqrsfz,Bsqryxq,Bsqwjurl,Status,Flag,Issalerid,Issbzcz,Fzsj,Isjky,Jkycj,Jkydlid,Isxy,XyValidity, Memo,Isyphf,issb,Isjkzcz,Isjkjybg,memo1,memo2,memo3,memo4,memo5,PzDate from nsaler_product where salerproductid=@tempSPid select @cnn=@@rowcount,@err=@err+@@error
--3.2.3开始删除 delete from nsaler_product where salerproductid=@tempSPid select @cnn=@@rowcount,@err=@err+@@error if @err>0 begin break end end
end
if @err>0 begin set @succ=0 rollback tran end else begin set @succ=1 commit tran end