Avatar of atoncelli
atoncelli asked on

Need to create SQL query with time filer

Hello,
 I have running ClearQuest on Windows and I am trying to create a query that has a time filter.  In a nutshell, I want to query for all the defects that are not closed and the ones that are closed but only in the last 15 days.  I tried to create the query but I can get it to work only if I use a specific day and time (ts).  Here are my queries.

This one works fine:

select distinct T1.dbid,T1.id,T1.title,T2.name from Defect T1,statedef T2,project T4 where T1.state = T2.id and T1.project = T4.dbid and (T1.dbid <> 0 and ((T4.name = 'Project 1' and ((T2.name = 'Closed' and T1.closed_date >= {ts '2008-05-12 04:00:00'}) or ((T2.name <> 'Closed' or T1.state = 0)))))) order by T1.id ASC

But if I change the time to use sysdate it doesn't work anymore:

select distinct T1.dbid,T1.id,T2.name, T1.title from Defect T1,statedef T2,project T3 where T1.state = T2.id and T1.project = T3.dbid and (T1.dbid <> 0 and (( ( (T2.name <> 'Closed' or T1.state = 0) or (T2.name = 'Closed' and T1.closed_date >(sysdate - 15 ))and T3.name = 'Project 1'))) order by T1.id ASC

Any suggestions?
Thanks
Microsoft SQL Server

Avatar of undefined
Last Comment
atoncelli

8/22/2022 - Mon
YZlat

use getdate instead
YZlat

also you cannot subtract 15 days this way, use DateDiff
YZlat

I meant DateAdd
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
YZlat

DATEADD(day, 15, sysdate)

or

DATEADD(day, 15, getdate())
ASKER CERTIFIED SOLUTION
YZlat

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
atoncelli

sysdate doesn't work but getdate() does!
Thanks a lot.