I want to create a query like the following, But im unsure of how to code it correctly, I want it to return all bookings within 1 hour of a StartTime, Here is what i came up with:
SELECT BookingId, StartTime
FROM Booking
WHERE StartTime <=> 1.00
Is the possible? or Is there a way round it?
Everything ive found on the web hasn't been about using Greater than, Equal to and Less Than all in the same query.
<= (Less Than or Equal To) (Transact-SQL)
Here is the answer – You can use either != or <> both in your queries as both technically same but I prefer to use <> as that is SQL-92 standard.
While some databases like sql-server support not less than and not greater than, they do not support the analogous not-less-than-or-equal-to operator ! <=.
Supposing you use sql server:
WHERE StartTime BETWEEN DATEADD(HOUR, -1, GetDate())
AND DATEADD(HOUR, 1, GetDate())
If start time is a datetime type then you can use something like
SELECT BookingId, StartTime
FROM Booking
WHERE StartTime >= '2012-03-08 00:00:00.000'
AND StartTime <= '2012-03-08 01:00:00.000'
Obviously you would want to use your own values for the times but this should give you everything in that 1 hour period inclusive of both the upper and lower limit.
You can use the GETDATE() function to get todays current date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With