Home > OS >  Get all rows with a list of date between two date columns in SQL
Get all rows with a list of date between two date columns in SQL

Time:11-26

I have a table named tableA which has two date columns. Currently, I am using the below query to fetch data.

"select * from tableA where IN_Date between date1 and date2"

IN_DATE is input param from the proc

Now instead of one date IN_DATE, I want to pass a list of dates but I am not sure how to update the query. Please help.

TableA

id date1 date2

CodePudding user response:

First of all want to clear that.. what's the data type of date Columns and which format are you using to store? What format you are passing in IN_DATE ?

CodePudding user response:

The solution to your problem

select * from tableA where (
    (IN_Date between date1 and date2) or 
    (IN_Date between date3 and date4) or 
    (IN_Date between date5 and date6)
)
  • Related