Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-04
7
Medium Priority
?
336 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-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

618 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