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

  • Home
  • SEARCH
  • 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 8778391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:31:35+00:00 2026-06-13T19:31:35+00:00

I need to insert several rows into a SQL Server database based on Start

  • 0

I need to insert several rows into a SQL Server database based on Start Date and End Date textboxes.

E.G. tbStartDate.Text = "25/12/2012" and tbEndDate.Text = "29/12/2012" therefore I need to insert individual rows for the following dates:

25/12/2012
26/12/2012
27/12/2012
28/12/2012
29/12/2012

Please can you help me with the necessary T-SQL to achieve this?

  • 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-13T19:31:36+00:00Added an answer on June 13, 2026 at 7:31 pm

    As always there are a few ways. Here are some of them:

    1. You can write code in your app that loops through the days and inserts a single record per day. (generally the worst design)

    2. You can call some SQL script to do it all in the database.

    3. You can wrap up your SQL script in a stored procedure and pass in the start and end date and get the stored procedure to do it for you.

    4. You can cross join to a pre existing tally table and use it to generate your records.

    If you can provide

    -the version of SQL Server that you’re using

    -what the table looks like

    -whether you’re using C# or VB

    then we can help further as it can be difficult to pass dates into databases. It can be particularly difficult if you do not validate them.

    Anyway here is option 3 for you.

    CREATE PROC dbo.t_test 
    @StartDate DATETIME,
    @EndDate DATETIME
    AS
    
    WHILE @StartDate <= @EndDate
    BEGIN
        INSERT INTO YourTable(YourDateField) VALUES (@StartDate)
        SET @StartDate = DATEADD(d,1,@StartDate)
    END
    

    Then you need to call this stored procedure (called dbo.t_test) from ASP.Net and pass in your two date parametes as dates.

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

Sidebar

Related Questions

I need to insert many sql rows into oracle database very fast. IndexData is
I need to import data from a file into a Microsoft SQL Server database.
I need to retrieve data from several rows and then insert the results into
I need to insert multiple checkbox text into a column in a mssql database,
Need to insert selected text on the page into textarea. There must be some
I need to insert about 1.8 million rows from a CSV file into a
i need to insert values of several elements into one cdata... here is my
I need to insert a polygon into a postgresql table polygontable and then return
I need to insert a huge amount of data into different tables within my
I need to insert a tab into a textarea when a tab is clicked

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.