Home > Software design >  SQL Server Finding date in between
SQL Server Finding date in between

Time:01-31

I have table like below,

In Realtime scenario I have more rows for testing purpose I am attaching only two rows. [Table]

Value Start Date End Date
10 30-Jun-15 30-Jun-16
20 30-Jun-16 31-Oct-16

If I requested start date as ' 31-JUL-2016' and end date as '31-AUG-2016', I need to get only row 2(Second row from table) in above table.

If I requested start date as ' 31-AUG-2015' and end date as '31-AUG-2016', I need get all two rows (All row from table) in above table.

How I can achieve this in SQL Server?

CodePudding user response:

SELECT * FROM your_table 
 WHERE '20160731' <= EndDate 
 AND '20160831' >= StartDate;

SELECT * FROM your_table
 WHERE '20150831' <= EndDate
 AND '20160831' >= StartDate;
  • Related