score:1
This query will find bookings that overlap the specified arrival and departure date. It assumes departure date is exclusive (i.e. guest can arrive on the day the previous guest departs):
SELECT *
FROM Bookings
WHERE RoomId = 1 AND @DepartureDate > ArrivalDate AND DepartureDate > @ArrivalDate
-- @Arrival/Departure dates are the ones you want to check
Given this query it is trivial to find available rooms.
score:1
If you want other bookings at the same time:
Select b.*
From Bookings
Where RoomId = 1 And
ArrivalDate <= '2018-09-21' and
DepartureDate >= '2018-09-20';
The logic is simple. Two periods overlap if one starts on or before the second ends. And, the first ends on or after the second starts. This assumes the periods are inclusive of the end points. You can adjust the <=
(to <
) and >=
(to >
) if they are exclusive.
If this returns no records, then the period (2018-09-20 - 2018-09-21) is free for a new booking.
Source: stackoverflow.com
Related Query
- Find bookings that conflict with given arrival / departure dates
- How to find keys in a Dict<int,List<Tuple<string,string>>> such that the list contains elements with given Item1 and Items
- Using LINQ, how do I find an object with a given property value from a List?
- Given UIElementCollection, find all elements that have StyleA, and change them to StyleB in WPF
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- Linq: Method that returns first instance with given type
- Find all articles that contain words with linq
- How can I find all data with a given time span
- Does a code that combines single() with yield make any sense?
- How to find highest level descendants with a given name
- Find object in list with given property value then find dictionary value
- LINQ/Lambda expression: Join lists and find the average counts of data with the given formula
- Given a list of color objects, find the most/least frequently existing color, and return that as a color object
- How to find all objects with an attribute that matches any of the values in another collection?
- Fastest way to find records that end with key
- C# Linq query to find strings in an array that end with strings in another array
- Using LINQ EF query to get all dates that fall in given months
- Find all objects with list attribute element that exist in another list
- Union 2 lists with additional content change for ID that occurs in both source lists
- Writing code that can work with multiple database objects
- partition a number range based on a size and then find the start of a partition for a given number in that range
- Find items that are similar amongst them in List in C# with nested For loops and Linq
- Using Linq, how do I check that a booking does not conflict with an existing booking?
- Using XPath within a single XElement to find only nodes that has a child node with specific Attribute
- Implementation for a method that, with a given string, generates all its possible partitions that are a palindrome, using Linq methods
- How do I find all parent objects that do not have child object with specific property?
- Find a certain value from a source collection in a target collection of different type with linq
- how can i find a list item with a list item's given parameter?
- Code that Worked with MultiView fails with Wizard ASP.NET
- SQLite and LINQ: find all objects that have a sub list with all ids present in a supplied list of IDs
More Query from same tag
- Select object fields into a map using Linq
- Is there a way of using orderby in a forloop C#?
- Linq IEnumerable Concat not working for list of objects containing second list as child object
- Linq: forward looking condition
- how to query over a list of numbers in line
- Replacing CompareTo with LINQ for array elements
- Make a new generic list from a list within a list in Linq with lambda expressions?
- How to store a List of IGrouping<int, object> to single List<T>?
- Overriding or ignoring undeclared entities in C# using LINQ
- Expression Tree Null VisitMember
- join using lambda expressions and retrieving the data
- LINQ to CRM - OR in Where clause
- convert SQL to LINQ not working
- Sorting a list by numeric value, alphabetic value and then a symbol
- Xml Linq Find Element After another Element
- ServiceStack OrmLite "Like" Linq
- Convert Method to Linq Expression for query
- converting c# lambda expression LINQ to vb.net
- Trim String value with particular pattern in C#.NET
- Linq to Generic list C# Data Filtering issue
- string.Contains as a predicate not a function call?
- Performance of Skip and Take in Linq to Objects
- Does the LINQ Expression API offer no way to create a variable?
- Elvis operator in a casting invocation chain
- Return the same instance type as the input type in generics
- Linq Return List of Objects after max effective From Date
- Count groups using linq
- Deserializing JSON using JSON.NET
- Invalid column sqlException in Linq query after update to Core 2.0
- LINQ to Object comparing two lists of integer for different values