Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7926923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:03:01+00:00 2026-06-03T19:03:01+00:00

I have a table |Start Date|End Date |Value|Avgerage Value Per Day| |2011-01-01 |2012-01-01| 730

  • 0

I have a table

|Start Date|End Date |Value|Avgerage Value Per Day|

|2011-01-01 |2012-01-01| 730 | 2|

I want to turn this table into a View

|Date| Average Value |

2011-01-01 | 2

2011-01-02 | 2

2011-01-03 | 2

…..

2011-12-31 | 2

Is is possible without using temp table to generate a list of date?
Any ideas?

Edit

Thanks both of the answers

With recursive view is similar as temp table

I do worry about the performance in a view, caz the view later will be involved in other processes.

I’ll try recursive view then, if it doesn’t fit, I may just use an hard code date list table.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:03:02+00:00Added an answer on June 3, 2026 at 7:03 pm

    Yes you can. This generates the days from the input set and then gives you the ranges you need

    Though this technically internally is like temp tables you can create a recursive view :

    Create View TestView as
        with Data As -- Pretends to be your table of data replace with  select from your tables
        (
            select Cast('2012-05-01' as DATETIME) [Start Date], Cast('2012-05-02' as DATETIME)  [End Date], 2  [Avgerage Value Per Day]
            union all
            select Cast('2012-04-01' as DATETIME) [Start Date], Cast('2012-04-05' as DATETIME) [End Date], 3  [Avgerage Value Per Day]
        )
        ,AllDates as -- generates all days
        (
             select cast('1900-01-01' as datetime) TheDate
             union all
             select TheDate + 1
             from    AllDates   
             where   TheDate + 1 < '2050-12-31'
        )
        select TheDate [Date], o.[Avgerage Value Per Day]
        from    AllDates
        join Data o on TheDate Between o.[Start Date]   AND   o.[End Date];
    

    you can the query it but you need to ensure that you specify a recursion limit

    select * from TestView
    OPTION (MAXRECURSION 0)
    

    this gives this result

    Date                        Avgerage Value Per Day
    2012-04-01 00:00:00.000 3
    2012-04-02 00:00:00.000 3
    2012-04-03 00:00:00.000 3
    2012-04-04 00:00:00.000 3
    2012-04-05 00:00:00.000 3
    2012-05-01 00:00:00.000 2
    2012-05-02 00:00:00.000 2
    

    You can see that from the test data I wanted May 1-2 and April 1-5

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 columns in my table - start date and end date, which
I have a (MySQL) table with two date/time fields: start and end (each of
I have a table with three date fields, a start date, mid-term date, and
We have a table that lists start and end dates for service time. I
I have a table called Sessions with two datetime columns: start and end. For
My goal is to return a start and end date having same value in
I have a table that has multiple records with a start date (PlacementDate) and
i have these tables: table 1 : date | idcurrency | total 2011-10-11 |
I'm writing a report that needs to display a value per day. I have
I have a table like this: date_start date_end account_id product_id 2001-01-01 2001-01-31 1 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.