[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

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

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
-cr-
Asked:
-cr-
1 Solution
 
Saqib KhanSenior DeveloperCommented:
Where A.PickupDateTimeScheduled BETWEEN DateAdd("hh", -24, A.PickupDateTimeScheduled) AND getDate()
0
 
James MurrellProduct SpecialistCommented:
where A.PickupDateTimeScheduled BETWEEN DateAdd("hh", -24, A.PickupDateTimeScheduled) AND getdate()
0
 
James MurrellProduct SpecialistCommented:
whoops sorry adilkhan yours not there when i posted
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
Mark WillsTopic AdvisorCommented:
Would be inclined to simply do :

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

0
 
Mark WillsTopic AdvisorCommented:
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
 
-cr-Author Commented:
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
 
Mark WillsTopic AdvisorCommented:
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now