-2

I have a table with the below data.

EmployeeName Country TravelFromDate TravelToDate
A India 06/01/2021 06/18/2021
B Nepal 06/10/2021 06/15/2021
c Bhutan 06/12/2021 06/17/2021

Now I have two textbox(FromDate and ToDate) in web app where I select date '06/10/2021' and '06/11/2021'. So as per logic 3 records should come as 3 employess are travelling between this two dates.

Now what will the sql query for this scenario.

Dale K
  • 21,987
  • 13
  • 41
  • 69
Jagat
  • 1
  • 1
  • Please show your attempt – Dale K May 07 '22 at 07:01
  • 1
    If you want a SQL query then this question has nothing to do with C# or ASP.NET. SQL is SQL, regardless of the application type or language. Furthermore, SO is not a code-writing service. If you want SQL code then learn to write SQL code. If what you write doesn't work as expected then show us what you did, tell us what you expected and what actually happened. – user18387401 May 07 '22 at 07:03
  • Actually I can't understand what will be the logic to implement 'where' condition. I wrote 'select* from test where TravelFromDate > CONVERT(datetime,'2021-06-10') and TravelToDate > CONVERT(datetime,'2021-06-11') query but it is not working . – Jagat May 07 '22 at 07:21
  • See the [following](https://stackoverflow.com/questions/749615/does-ms-sql-servers-between-include-the-range-boundaries) – Karen Payne May 07 '22 at 08:37
  • Unless you don't want overlap, and instead want within on which case it's `@startDate >= TravelFromDate AND @endDate <= TravelEndDate` – Caius Jard May 07 '22 at 09:16

0 Answers0