Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


split a record by date span

split a record by date span

split a record by date span

can someone help me to split ONE  record  into multiple lines with the same batch_id if the service start date and service end date are more than 30 days apart.

For e.g  the current data is in the format below
batch_id     service start date    service end date
99999            2/15/2008            4/25/2008
Need to be transformed to     
batch_id    service start date    service end date
99999             2/15/2008            3/16/2008
99999             3/16/2008            4/15/2008
99999             4/15/2008            4/25/2008

i need a SQL solution.

any help is appreciated.

RE: split a record by date span

You could use calendar view :


select  bat.batch_id
    ,   cal.calendar_date   as start_date
    ,   case when cal.calendar_date + 30 >= bat.end_date
                then bat.end_date
            else cal.calendar_date + 30
        end as end_date
from    batch   as bat
    inner join
        sys_calendar.calendar   as cal
        on  (cal.calendar_date - bat.start_date + 1) mod 30 = 0
        and cal.calendar_date between bat.start_date and bat.end_date

RE: split a record by date span

Thanks al1024!

my solution was very very close to what you suggested.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close