sql - I am trying to write a query to track use of terminals. I want to show all terminals that have not had activity for 1 year -


i trying write query track use of pc terminals. want show pc terminals have not had activity 1 year. query trying use , returns 0 results though know have terminals have not been used. dates in date/time formats (2016-06-22 14:38:12.000)

select distinct     t.terminalid,     t.terminalname     terminal t inner join     pos_payments p     on p.terminalid = t.terminalid     transactiondatetime < '7/29/2015' , transactiondatetime !> '7/30/2015' order t.terminalid  

use group by , max():

select t.terminalid, t.terminalname terminal t inner join       pos_payments p       on p.terminalid = t.terminalid group t.terminalid, t.terminalname having max(transactiondatetime) < '2015-07-29' order t.terminalid ; 

note use of iso standard yyyy-mm-dd date format.

if want based on current date:

having max(transactiondatetime) < dateadd(year, -1, getdate()) 

(and might want cast date rid of time component.)


Comments