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
 General SQL Server Forums
 New to SQL Server Programming
 Extracting Data Where Tomorrow's Date Is Used

Author  Topic 

KingCarlos
Yak Posting Veteran

74 Posts

Posted - 2009-10-25 : 22:38:40
Hi, I am trying to have a report built which gets the next_call_date a day before the next call date.

In otherwords the report is run today, October 26 2009 and I want it to capture all data that has the value of October 27 2009.

And then the day after October 27 2009 and I want it to capture all data that has the value of October 28 2009.

How do I build such a sql query

KingCarlos
Yak Posting Veteran

74 Posts

Posted - 2009-10-25 : 22:56:57
Actually thinking I can have it built on the same date earlier monring so that the report can be sent before office hours

The problem with this SQL Script is that the getdate includes the time whereas the next_call_date format is YYYY-DD-MM

select next_call_date, * from contacts
where next_call_date = getdate()

I was also fooling arou8nd with this sql script

select next_call_date, * from contacts
where next_call_date = dateadd (d,1,getdate()ltrim,10))
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-10-25 : 23:28:45
where next_call_date = dateadd(day, datediff(day, 0, getdate()), 1)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-25 : 23:47:38
[code]
where next_call_date >= dateadd(day, datediff(day, 0, getdate()), 1)
and next_call_date < dateadd(day, datediff(day, 0, getdate()), 2)
[/code]


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

Go to Top of Page

KingCarlos
Yak Posting Veteran

74 Posts

Posted - 2009-10-26 : 00:27:24
thanks russel your solution worked a trest !!!
Hi khtan I will try yours also, thanks !!
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-10-26 : 00:29:49
if you next_call_date contains time, then you have to use the query i posted, if not russell's query is sufficient


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

Go to Top of Page
   

- Advertisement -