Nisha Verma
Nisha Verma

Reputation: 101

how to get each and every Date in between selected date (in DB2)

Dear StackOverflow Community,

as a New to DB2 ,i have a a query may be its a very basic question for you, please share your knowledge.

i have a start date and End Date. I need a list of each and every date in between.

Its ok with me ,if it creates a temp table no issue. Thanks in Advance

Upvotes: 0

Views: 93

Answers (1)

Rams
Rams

Reputation: 2169

You can generate the dates between start and end dates by using Recursive CTE expression. Try below code

    with cte(your_columns,startdate,enddate)
    as (select your_columns,startdate,enddate,startdate 
as derDate
    from yourTable
    union all
    select your_columns,startdate,enddate,derDate+1 
    from cte where 
    derDate<=endDate)
    select * from cte

Upvotes: 1

Related Questions