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
 SQL that gives me Jobs due tomorrow?

Author  Topic 

Maverick_
Posting Yak Master

107 Posts

Posted - 2012-08-22 : 08:58:14
Hi guys,

This might be something really simple but I am after an SQL statement that only gives me results where commitment time is due for tomorrow. (i.e. excludes results due 2 days time, next week etc)

The field related to this is enquiry_commitment.commit_target_time.

The filter should work for anytime the query is run and only focus on the next day's commitments.

I think I need to use Date_Add but I couldn't get it to work. And I also tried: trunc(enquiry_commitment.commit_target_time,'DD') > trunc(SYSDATE,'DD')+1 but it did not work.
Does anyone have a SQL code to share for this?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-08-22 : 09:13:57
See http://weblogs.sqlteam.com/peterl/archive/2008/10/10/Keep-track-of-all-your-jobs-schedules.aspx


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Maverick_
Posting Yak Master

107 Posts

Posted - 2012-08-22 : 09:20:38
Hi thanks for the link but I could see any SQL in there that restricts it to tomorrow.
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-08-22 : 10:00:00
Maybe this, assuming the enquiry_commitment.commit_target_time is of date/datetime type?
SELECT * FROM YourTable
WHERE
enquiry_commitment.commit_target_time >= DATEADD(dd,DATEDIFF(dd,-1,GETDATE()),0)
AND enquiry_commitment.commit_target_time < DATEADD(dd,DATEDIFF(dd,-2,GETDATE()),0)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-08-22 : 10:07:57
quote:
Originally posted by Maverick_

Hi thanks for the link but I could see any SQL in there that restricts it to tomorrow.


There are two input parameters in the procedure header
  @startDate DATETIME,
@endDate DATETIME
which you can use to restrict the output for tomorrow.
Or current week?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -