2016-11-30 1 views
1

Donc mon problème est que je dois faire une procédure qui va multiplier tous les prix dans ma table de produits avec 0,8 si le produit ne s'est pas vendu pour le nombre X de mois.Procédure stockée donnant "discount" basé sur X nombre de mois à partir de la date d'aujourd'hui

Je ne semblons pas en ce moment pour aller plus loin que cela:

GO 
CREATE PROC newprice(@numberofmonth int) 
AS 
BEGIN 
DECLARE @today datetime 
SET @today = GetDate() 
SELECT product.productid, product.name 
FROM orders JOIN orderitem on orderitem.orderid = orders.orderid 
      JOIN product on product.productid = orderitem.productid 
WHERE orders.orderdate > (SELECT DATEADD(month, [email protected], @today)) 

UPDATE product set price = price * 0.8 where 
END 

tout espoir est assez transparent pour lire et comprendre sans aucune autre description. Je travaille avec SQL Server.

Répondre

0

Je comprends pas votre problème completly.i juste supposons que votre besoin regarder ce

GO CREATE PROC newprice(@numberofmonth int) 
AS 
BEGIN 
DECLARE @today datetime 
SET @today = GetDate() 
UPDATE product set price = price * 0.8 FROM orders JOIN orderitem on orderitem.orderid = orders.orderid JOIN product on product.productid = orderitem.productid WHERE orders.orderdate > 
(SELECT DATEADD(month, [email protected], @today)) 
END 
+0

qui a fonctionné parfaitement. Merci beaucoup – MrBawsEnough

0
CREATE PROCEDURE newprice(@numberofmonth int) 
AS 
BEGIN 

UPDATE product 
SET price = price * 0.8 
FROM product 
JOIN orderitem on product.productid = orderitem.productid 
JOIN orders on orderitem.orderid = orders.orderid 
WHERE orders.orderdate > (DATEADD(month, [email protected], GETDATE())) 

END 
0

S'il vous plaît vérifier si elle fait ce que vous avez besoin:

DECLARE @today datetime 
SET @today = GetDate() 

Select * FROM product 
--UPDATE product SET price = price * 0.8 
WHERE not exists (
    SELECT product.productid, product.name 
    FROM orders 
    INNER JOIN orderitem on orderitem.orderid = orders.orderid 
    WHERE orders.orderdate > (SELECT DATEADD(month, [email protected], @today)))