Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help with query

Author  Topic 

jigsatics
Starting Member

18 Posts

Posted - 2006-01-11 : 13:11:00
Hi!

I have a DB with this fields:
MID - primary key
EVENT - varchar(2)
EVENT_DATE datetime (format mm/dd/yyyy)

I need to design a query that will pickup records from DB with EVENT = '02' and EVENT_DATE equal or earlier than 18 days from the date the query was executed.

In this example, the query should display these 2 records if ran today:
MID EVENT EVENT_DATE
01 02 12/25/2005
02 02 12/20/2005

But not this:

MID EVENT EVENT_DATE
03 03 12/25/2005
04 02 01/01/2006

Any help will be greatly appreciated.



$3.99/yr .COM!
http://www.greatdomains4less.com

nosepicker
Constraint Violating Yak Guru

366 Posts

Posted - 2006-01-11 : 20:04:31
SELECT mid, event, event_date
FROM YourTable
WHERE event = '02'
AND event_date <= DATEADD(d, DATEDIFF(d, 0, getdate()) -17, 0)
Go to Top of Page
   

- Advertisement -