/*------------------------
*判断定单价格总数唯一
*先查找数据库,看价格总值(PriceTotal)是否存在相等,如果不存在插入该值
*如果存在,将(PriceTotal-10)和PriceTotal之间分成1000份,差值为0.01
*查找(PriceTotal-10)和PriceTotal之间最小值,如果存在就将MIN最小值-0.01插入数据
*如果MIN等与PriceTotal-10说明在(PriceTotal-10)和PriceTotal之间数据都存在
*则取(PriceTotal)为PriceTotal-10将其再插入,递归进行
*

*/
CREATE    PROCEDURE judgeOrdersADD
(
@OrderID varchar(50) ,
@UserID int ,
@PVTotal decimal(20,2) ,
@PriceTotal decimal(20,2) ,
@CreateTime datetime ,
@OrderFlag int
)
AS
   declare @intCount int   --是否存在相等
   declare @tempPrice decimal(20,2)  --定单总价格-10
   declare @MinPrice decimal(20,2)   --最小总价
   declare @InToPrice  decimal(20,2)
   select @intCount=count(OrderID) from orders where PriceTotal=@PriceTotal

   if @intCount=0

     insert into orders(OrderID,UserID,PVTotal,PriceTotal,CreateTime,OrderFlag)
     values(@OrderID,@UserID,@PVTotal,@PriceTotal,@CreateTime,@OrderFlag)

   else
       set @tempPrice=@PriceTotal-10;

       select @MinPrice=min(PriceTotal) from  orders where PriceTotal between @tempPrice and @PriceTotal
      
        if @MinPrice=@tempPrice  --如果最小值等于@PriceTotal-10既@tempPrice
          begin
           set @PriceTotal=@MinPrice   --查找下一个10等分

           exec judgeOrdersADD @OrderID,@UserID,@PVTotal,@PriceTotal,@CreateTime,@OrderFlag

         end

         else
         begin
            set @InToPrice=@MinPrice-0.01
             insert into orders(OrderID,UserID,PVTotal,PriceTotal,CreateTime,OrderFlag)
              values(@OrderID,@UserID,@PVTotal,@InToPrice,@CreateTime,@OrderFlag)
           end
          
 RETURN

 


GO

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
  • 2022-12-23
  • 2021-12-03
  • 2021-11-16
  • 2021-04-08
猜你喜欢
  • 2021-07-19
  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案