Solved

Getting everything that is = 24 hours from getdate() using a stored procedure.

Posted on 2008-10-04
7
325 Views
Last Modified: 2012-05-05
I have a scheduled task that runs hourly. Currently it selects items where A.PickupDateTimeScheduled  is within the hour. What I need is to have the stored procedure attached select items that are += to 24 hours, but not 25 hours because the process should pick those items up the following hour. The minutes I am not too concerned about. I hope I am clear in what I am looking for. Thanks in advance for any assistance.
CREATE procedure [dbo].[usr_sel_reservations_12hours]  
as
Set NoCount On
Select Distinct A.ResNO, A.Pickup_City, A.VehicleNoActual As 'VehicleNumber', A.PreferredVehicleType As 'VehicleType', A.NumOfPassengers, A.PassengerFirstName, A.PassengerLastName, A.PickupDateTimeScheduled, A.Pickup_AddressOnLocation, A.Pickup_City,A.Pickup_State, A.Pickup_StreetName, A.Pickup_StreetNo, A.Pickup_ZipCode, A.Pickup_DispatchZoneState, A.Pickup_FlightAirlinePK, A.Pickup_FlightNo, A.Pickup_FlightType, A.Pickup_PlaceDataSource,
				A.Pickup_LandmarkId, A.Pickup_LandmarkName,A.Dropoff_FlightNo, A.DropOff_AddressOnLocation, A.DropOff_AddressLine2, A.DropOff_PlaceDataSource, A.DropOff_LandmarkName, B.EmailAddress, B.Dropoff_FlightDestinationCity, B.Dropoff_FlightDestinationAirport As 'DestinationAirport', B.Dropoff_FlightDestinationCity As 'FlightDestinationCity', B.Dropoff_FlightFAADepartureTime As 'FlightDepartureTime', A.DropOff_StreetNo, A.DropOff_StreetName, A.DropOff_City, A.Dropoff_State, A.Dropoff_Zipcode,A.DropOff_FlightNo,A.DropOff_FlightAirlinePK
From tbRideResCurMaster A
Join tbRideResCurMasterExt B
On A.ResNo = B.ResNo
Where A.PickupDateTimeScheduled BETWEEN dateadd(hour, -1, getdate()) AND getdate() And B.EmailAddress <> '' And B.EmailAddress Is Not NULL And B.Dropoff_FlightDestinationCity Is Not NULL And B.Dropoff_FlightDestinationCity <> ''
GO

Open in new window

0
Comment
Question by:-cr-
7 Comments
 
LVL 23

Expert Comment

by:Saqib Khan
ID: 22641601
Where A.PickupDateTimeScheduled BETWEEN DateAdd("hh", -24, A.PickupDateTimeScheduled) AND getDate()
0
 
LVL 31

Expert Comment

by:James Murrell
ID: 22641629
where A.PickupDateTimeScheduled BETWEEN DateAdd("hh", -24, A.PickupDateTimeScheduled) AND getdate()
0
 
LVL 31

Expert Comment

by:James Murrell
ID: 22641632
whoops sorry adilkhan yours not there when i posted
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 51

Expert Comment

by:Mark Wills
ID: 22645040
Would be inclined to simply do :

Where A.PickupDateTimeScheduled >= DateAdd("hh", -24, getDate())

0
 
LVL 51

Expert Comment

by:Mark Wills
ID: 22645047
Hang on, might have misread the requirement - could you please describe :  that are += to 24 hours ?  Seems that it is going to do a lot of repeat work the next hour it runs, are you saying that every hour it should run for a period which is "yesterday" ? Or am I thinking too much again...
0
 

Author Comment

by:-cr-
ID: 22670084
Yes the samples do not do what I need. I think I am close to getting this to work the way I want.
I have attached a snippet I have been working on, but I need it to do a round to the nearest hour which I believe it is doing. I also need it to then add 24 hours so I am only grabbing reservations exactly 24 hours in advance.
DateAdd(mi, Round(DateDiff(mi,0, A.PickupDateTimeScheduled ) / 30,0) * 30,0) = DateAdd(mi, Round(DateDiff(mi,0, GetDate()) / 30,0) * 30,0)

Open in new window

0
 
LVL 51

Accepted Solution

by:
Mark Wills earned 500 total points
ID: 22671345
OK, so it should be 24 hours from "now", so, if today (gmt +10:00) is 9th October at 5:00Am, then we want pickupdatetimescheduled that is 10th October 5:00am - correct ?

first try :   select convert(varchar(13),getdate() + 1,120)    -- gives you "yyyy-mm-dd hh"

then try:  Where convert(varchar(13),A.PickupDateTimeScheduled,120) = convert(varchar(13),getdate() + 1,120)


0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question