If From_Date
and To_Date
are variables:
DECLARE @From_Date date = '2016-02-22',
@To_Date date = '2016-05-16'
SELECT *
FROM YourTable
WHERE DateField between @From_Date and @To_Date
If not then:
SELECT *
FROM YourTable
WHERE DateField between '2016-02-22' and '2016-05-16'
In another table:
SELECT y.*
FROM YourTable y
INNER JOIN TableWithDate d
ON y.DateField between d.From_Date and d.To_Date
To get output you want with recursive CTE (assuming that in [Table A]
is string with '2016-02-22'
, '2016-02-29'
values for From_Date
, To_Date
):
;WITH recurs AS (
SELECT DATEADD(day,1,From_Date) as date_, To_Date
FROM [Table A]
UNION ALL
SELECT DATEADD(day,1,date_), To_Date
FROM recurs r
WHERE date_ < DATEADD(day,-1,To_Date)
)
SELECT date_
FROM recurs
Output:
date_
2016-02-23
2016-02-24
2016-02-25
2016-02-26
2016-02-27
2016-02-28