DECLARE @orderno varchar(50) declare @product_no varchar(50) declare @color varchar(50) declare @product_size varchar(50) DECLARE CusCursor CURSOR FOR SELECT orderno FROM tbl_5351_24 OPEN CusCursor FETCH NEXT FROM CusCursor INTO @orderno WHILE (@@FETCH_STATUS = 0) BEGIN --select @product_no=product_no,@color=color,@product_size=product_size from shop.dbo.tbl_order where orderno=@orderno set @product_size=(select product_size from shop.dbo.tbl_order where orderno=@orderno) set @product_no=(select product_no from shop.dbo.tbl_order where orderno=@orderno) update shop.dbo.tbl_order set product_size='37' where orderno=@orderno update shop.dbo.tbl_product_store set number3=number3-1 where product_no=@product_no and color='21' and product_size='37' FETCH NEXT FROM CusCursor INTO @orderno END CLOSE CusCursor DEALLOCATE CusCursor