2016-11-30 15 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))) 
相关问题