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 7615209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:35:20+00:00 2026-05-31T02:35:20+00:00

I have a table and every row will have an ID , Date ,

  • 0

I have a table and every row will have an ID, Date, and Value column. I want it so that every time a person accesses a page on my web site, a stored procedure will run that will insert a row for each day within a range IF that day doesn’t already exist.

The date range will be from 01/01/2012 until the Saturday before the current day (the day the page was accessed). The ID will auto-generate and the Value field will remain NULL/blank.

For example, if I accessed the page today, I would want a record in the table for every day between 01/01/2012 until 03/03/2012.

  • 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-05-31T02:35:21+00:00Added an answer on May 31, 2026 at 2:35 am

    This gets all the days that don’t exist yet, and excludes rows after the previous Saturday.

    ;WITH d AS 
    (
      SELECT TOP (366) d = DATEADD(DAY, ROW_NUMBER() OVER (ORDER BY object_id), '20111231')
      FROM sys.all_objects
    )
    INSERT dbo.[a table]([Date])
      SELECT d FROM d 
      WHERE d NOT IN (SELECT [Date] FROM dbo.[a table])
      AND d <= DATEADD(DAY, 0-DATEPART(WEEKDAY, GETDATE()), GETDATE());
    

    Note that I assumed you would “reset” this once your calendar year rolled over.

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

Sidebar

Related Questions

Let's say I have a table that has user_id, date, score, and every user
I have a table where every row has a unique id. The last table
I have an app that needs to check a database table every minute. The
We have a database where every table name starts with WW. I want to
I have a table on which I want to perform some operations every hour.
I want to have an 'updateinfo' table in order to record every update/insert/delete operations
I have a table with a number of columns that will be used to
I have a database table with a UNIQUE key on a date column so
I have a table that will have 500,000+ records. Each record has a LineNumber
I have a table in in which every row contains a form. see below

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.