Avatar of MDauphinais1
MDauphinais1
 asked on

Split Date Range to Individual Dates

Is there a query that I can store on the SQL server that can take a result with a start date and end date and instead break it down to show that record for each date in the range?

For example:
A query outputs this record:      MyEventTitle   |   3/12/2008   |   3/15/2008

Instead of seeing that one line, I want to see this:

MyEventTitle   |   3/12/2008
MyEventTitle   |   3/13/2008
MyEventTitle   |   3/14/2008
MyEventTitle   |   3/15/2008

Basically the end date doesn't show and instead I see the record broken down by each date from the date range that was in the result.

I am doing this now with an RS.LOOP function while inserting records into a table but that seems redundant if I can just accomplish this while pulling the records in a query instead of having to insert them into yet another table.

I saw this posting which seems like it is on the right track for what I need but I want to be broken down for each date witihin a range and not each month:
https://www.experts-exchange.com/questions/23653806/Split-Date-Range-into-Months.html
Microsoft SQL Server

Avatar of undefined
Last Comment
MDauphinais1

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
reb73

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
aaronakin

If you're using SQL 2005, you can use a common table expression to do this.  Take a look at example 4 in my blog post.  http://aaronakinsql.wordpress.com/2009/01/21/recursive-common-table-expressions-part-2/
SOLUTION
Pavel Celba

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MDauphinais1

ASKER
reb73, once I create the function how would I then run a query from a table that has more data than just the dates?

For example:
EventTitle
ClientName
StartDate
EndDate
Phone

Would be:
EventTitle
ClientName
EventDate
Phone
SOLUTION
reb73

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
MDauphinais1

ASKER
Very cool, thanks for your help.

Thanks AngelIII! :)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck