2016-11-30 44 views
1

所以我的問題是,我必須制定一個程序,將產品表中的所有價格乘以0.8,如果產品沒有售出X數量幾個月。存儲過程給予「折扣」基於X從今天的月份數量

目前,我似乎無法得到任何進一步的比這

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 

希望一切是足夠透明的閱讀,沒有任何進一步的說明了解。我正在使用SQL Server。

回答

0

我不明白你的問題completly.i只是假設你需要看看這個

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

奏效完美。非常感謝 – 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

請檢查如果它讓你需要的東西:

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))) 
相關問題