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)
 Query using today's date

Author  Topic 

xzibited
Starting Member

5 Posts

Posted - 2008-08-14 : 21:30:48
All- I'm trying to write a query that will automatically pull data from just today (today being the day that the query is run). Currently I have this query:

select dateopened from event
where eventtype in ('Service Dispatch', 'Reprogram', 'Install')
and status NOT IN ('cancelled')
and DateOpened>=DateAdd(hh,-12,GetDate())


Obviously the problem is that this will also pull data from the previous day if it's run early enough in the morning. Anyone know of a different way to script this so that it just pulls data from today only when its run at any point in the day?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-14 : 21:57:50
[code]
select dateopened from event
where eventtype in ('Service Dispatch', 'Reprogram', 'Install')
and status NOT IN ('cancelled')
and DateOpened >= DateAdd(hh, -12, GetDate())
and DateOpened >= DateAdd(day, DateDiff(day, 0, getdate()), 0) -- DateOpened is greater or equal to today midnight

[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

xzibited
Starting Member

5 Posts

Posted - 2008-08-15 : 10:34:32
awesome, worked perfectly. Thanks!
Go to Top of Page
   

- Advertisement -