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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:45:12+00:00 2026-05-13T18:45:12+00:00

How to repeat the row values up to end date For Example Table1 Date

  • 0

How to repeat the row values up to end date

For Example

Table1

Date         Name   Dept 
-----------------------
12-02-2009   Raja   IT
13-02-2009   Ravi   CSE
14-02-2009   Ramu   ECE

From the above table value i want to repeat the value between the two dates from 12-02-2009 to 12-03-2009.

Expected Output

Date         Name   Dept 
--------------------------
12-02-2009   Raja   IT
13-02-2009   Ravi   CSE
14-02-2009   Ramu   ECE
15-02-2009   Raja   IT
16-02-2009   Ravi   CSE
17-02-2009   Ramu   ECE
18-02-2009   Raja   IT
19-02-2009   Ravi   CSE
20-02-2009   Ramu   ECE
...
...
12-03-2009

How to make a query for repeating the row values upto end date or is possible in vb.net by using while loop like

code

select max(date) from table

while max(date) < End Date

'Repeat the row values

end while

My Table Structue

Date Name Dept Time

12-02-2009   Raja   IT  09:00 
13-02-2009   Ravi   CSE 18:00 
14-02-2009   Ramu   ECE 10:00

Expected Output

Date Name Dept Time StartDate EndDate

12-02-2009   Raja   IT  09:00 12-02-2009 12-02-2009
13-02-2009   Ravi   CSE 18:00 13-02-2009 14-02-2009
14-02-2009   Ramu   ECE 10:00 14-02-2009 14-02-2009

…,

If StartDate is same value of Date column
For EndDate i have to check the time column, if time is greater than 17:00 it should display a next date in EndDate column.

Need SQL Query or VB.Net Code Help

  • 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-13T18:45:12+00:00Added an answer on May 13, 2026 at 6:45 pm

    You could try something like

    DECLARE @Table TABLE(
            Date DATETIME,
            Name VARCHAR(50),
            Dept VARCHAR(50)
    )
    
    INSERT INTO @Table SELECT '12 Feb 2009', 'Raja', 'IT'
    INSERT INTO @Table SELECT '13 Feb 2009', 'Ravi', 'CSE'
    INSERT INTO @Table SELECT '14 Feb 2009', 'Ramu', 'ECE'
    
    
    
    DECLARE @StartDate DATETIME,
            @EndDate DATETIME,
            @Count INT
    
    SELECT @Count = COUNT(1) FROM @Table
    
    SELECT @StartDate = '12 Feb 2009',
            @EndDate = '12 Mar 2009'
    
    --using CTE create a date range, and associated id per date
    ;WITH Dates AS (
            SELECT  @StartDate DateVal,
                    0 ID
            UNION ALL
            SELECT  DateVal + 1,
                    (ID + 1) % @Count
            FROM Dates
            WHERE DateVal + 1 <= @EndDate
    ),
    --using cte, create id per entry in the table you wish to repeat
    RowNumbers AS(
            SELECT  *,
                    ROW_NUMBER() OVER(ORDER BY Date) ID
            FROM    @Table
    )
    --join dates to table to repeat id generated ids.
    SELECT  *
    FROM    Dates d LEFT JOIN
            RowNumbers r on d.ID + 1 = r.ID
    

    Have a look at

    • Beginners guide to accessing SQL
      Server through C#

    • Using ADO.NET with SQL Server

    for executing queries with params from vb.net/c#

    EDIT

    To get the expected output, you can try

    DECLARE @Table TABLE(
            Date DATETIME,
            Name VARCHAR(50),
            Dept VARCHAR(50),
            Time VARCHAR(5)
    )
    
    INSERT INTO @Table SELECT  '12 Feb 2009','Raja','IT','09:00'
    INSERT INTO @Table SELECT  '13 Feb 2009','Ravi','CSE','18:00'
    INSERT INTO @Table SELECT  '14 Feb 2009','Ramu','ECE','10:00'
    
    SELECT  *,
            Date AS StartDate,
            CASE 
                WHEN CAST(LEFT(Time,2) AS INT) > 17 THEN Date + 1 
                ELSE DATE 
            END EndDate
    FROM    @Table
    

    Now you need to decide which date you want to use to order by in the ROW_NUMBER() line, or how you wish to repeat the rows by date.

    EDIT

    This is how you would insert values
    
    DECLARE @InsertTable TABLE(
            DateVal DATETIME,
            ID INT,
            Date DATETIME,
            Name VARCHAR(50),
            Dept VARCHAR(50)
    )
    
    DECLARE @Table TABLE( 
            Date DATETIME, 
            Name VARCHAR(50), 
            Dept VARCHAR(50) 
    ) 
    
    INSERT INTO @Table SELECT '12 Feb 2009', 'Raja', 'IT' 
    INSERT INTO @Table SELECT '13 Feb 2009', 'Ravi', 'CSE' 
    INSERT INTO @Table SELECT '14 Feb 2009', 'Ramu', 'ECE' 
    
    
    
    DECLARE @StartDate DATETIME, 
            @EndDate DATETIME, 
            @Count INT 
    
    SELECT @Count = COUNT(1) FROM @Table 
    
    SELECT @StartDate = '12 Feb 2009', 
            @EndDate = '12 Mar 2009' 
    
    --using CTE create a date range, and associated id per date 
    ;WITH Dates AS ( 
            SELECT  @StartDate DateVal, 
                    0 ID 
            UNION ALL 
            SELECT  DateVal + 1, 
                    (ID + 1) % @Count 
            FROM Dates 
            WHERE DateVal + 1 <= @EndDate 
    ), 
    --using cte, create id per entry in the table you wish to repeat 
    RowNumbers AS( 
            SELECT  *, 
                    ROW_NUMBER() OVER(ORDER BY Date) ID 
            FROM    @Table 
    ) 
    --join dates to table to repeat id generated ids. 
    INSERT INTO @InsertTable --INSERT VALUES HERE
    SELECT  d.DateVal,
            d.ID,
            r.Date,
            r.Name,
            r.Dept 
    FROM    Dates d LEFT JOIN 
            RowNumbers r on d.ID + 1 = r.ID
    OPTION (MAXRECURSION 0) --this is required.           
    
    SELECT *
    FROM @InsertTable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 314k
  • Answers 314k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can just add a Service Reference to your MVC… May 13, 2026 at 10:57 pm
  • Editorial Team
    Editorial Team added an answer Bruno, I think you should make a distinction here; you… May 13, 2026 at 10:57 pm
  • Editorial Team
    Editorial Team added an answer The preferred Locale for a user is available as a… May 13, 2026 at 10:57 pm

Related Questions

I'm writing an algorithm in PHP to solve a given Sudoku puzzle. I've set
I need to validate two user input fields against each other in seam. Field1
I'm using a couple of Grid s to format multiple GridViewColumn.CellTemplate s: <ListView SharedSizeScope=true>
I've been stumped with some SQL where I've got several rows of data, and
Please could you give me your thoughts on the following (especially if its advisable

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.