sql - How can I update a column (multiple rows) in a table with the lower value between 2 column in 2 tables? -
i need compare comision of seller , comision of product , put lower value in comision column in details.
table 1: details doc comision seller product 1 0 001 0101 1 0 001 0315 1 0 001 0425 2 0 001 0389 2 0 001 0315 table 2: products code description comision 0101 product 1 5 0315 product 2 7 0425 product 3 3 0389 product 4 8 . . . table 3: sellers code name comision 001 seller 1 6 002 seller 2 3 . . .
i did this:
declare @comisionvendedor float,@comisionproducto float, @comision float,@prod='0101' set @comisionvendedor=0 set @comisionproducto=0 select @comisionvendedor=comision vendedor join details on seller.code=details.seller details.doc=1 , prod=@prod select @comisionproducto=products.comision products join details on products.code=details.product details.doc=1 , prod=@prod if @comisionvendedor>@comisionproducto begin set @comision=@comisionproducto end else begin set @comision=@comisionvendedor end update details set comision=@comision details.doc=1 , product=@prod
it works fine 1 product. how can replace comision column of 3 rows doc number of 1?
you use printf command
Comments
Post a Comment