CREATEORALTER PROC [dbo].[CalculateStake] @CategoryIDint, @ProductIDsmallint , @ProdcutGroupIDsmallint, @PriceLimit [uftt_PriceLimit] readonly AS BEGIN SET NOCOUNT ON;
MERGEINTO [dbo].[PriceLimitation] t1 USING@PriceLimit t2 ON t1.UserID = t2.UserID AND t1.ProdcutGroupID=@ProdcutGroupID AND t1.CategoryID=@CategoryID AND t1.ProductID =@ProductID WHEN MATCHED THEN UPDATESET t1.StakeAmount = t1.StakeAmount + t2.StakeAmount WHENNOT MATCHED THEN INSERTVALUES(@CategoryID, @ProdcutGroupID, t2.UserID ,t2.StakeAmount, @ProductID); END
;with cte as( select@fromas num unionall select num +1as num from cte where num <@from+500 ) insert into@PriceLimit ([UserID],[StakeAmount],CategoryID,[ProductID],[ProdcutGroupID]) select num,100,@CategoryID,@ProductID,@ProdcutGroupID from cte option(MAXRECURSION 0);