2016-02-11 60 views

回答

4

試試這個:

SELECT * FROM Table 
WHERE lastdelivery <= dateadd(month, -6, getdate()) 
+0

這工作完美,非常感謝你! – necrofish666

+1

那你能接受我的回答嗎?:) @ ailinmcc666 –

+0

是的,抱歉,忘了! – necrofish666

1
  DECLARE @subscriptions TABLE 
      (
       OrderId int, 
       OrderName varchar(255), 
       lastDelivery date default getdate() 
      ) 

      INSERT INTO @subscriptions (OrderName, lastDelivery) 
      VALUES 
      ('Allen', '2015-05-20'), 
      ('Bob', '2015-06-20'), 
      ('Craig', '2015-07-20'), 
      ('David', '2015-08-20'), 
      ('Edward', '2015-09-20'), 
      ('Frank', '2015-10-20'), 
      ('George', '2015-11-20'), 
      ('Harry', '2015-12-20') 

      SELECT OrderName FROM @subscriptions 
      WHERE lastDelivery <= DATEADD(MONTH, -6, GETDATE()) 
1

使用DATEADD

查詢

select * from your_table_name 
where lastDelivery <= dateadd(month, -6, getdate()); 
相關問題