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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:48:16+00:00 2026-05-18T22:48:16+00:00

In some of the hours I insert data to DB with timestamp. I want

  • 0

In some of the hours I insert data to DB with timestamp. I want to have hourly view with rows without records filled with last record data :

Table

DateTime Value  
12     4  
15     6  

Desired Result

DateTime Value  
12       4  
13       4  
14       4  
15       6  
16       6  

It should be possible, but I can’t think about any effective way..

How can this be done?

  • 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-18T22:48:16+00:00Added an answer on May 18, 2026 at 10:48 pm

    OK having misread the question once and provided an answer that leaves the gaps efficiently; in order to get the last value out in sql you will need to loop the data which is less efficient.

    Create Table tblMyValues (MyHours int, MyValue int)
    Insert into tblMyValues select 12, 4
    Insert into tblMyValues select 15, 6
    Insert into tblMyValues select 15, 6
    
    
    Create Table tblResult (MyHour int, ReportValue Int)
    
    Declare @i Int = 0, @LastValue Int
    While @i <= 24
    Begin
    
    select @i = @i + 1
    Select @LastValue = coalesce(MyValue, @LastValue)
    From tblMyValues
    Where MyHours = @i
    
        insert into tblResult 
        Select @i, @LastValue
    
    End
    
    select * from tblResult
    drop table tblMyValues
    drop table tblResult
    

    This returns

    MyHour      ReportValue
    ----------- -----------
    1           NULL
    2           NULL
    3           NULL
    4           NULL
    5           NULL
    6           NULL
    7           NULL
    8           NULL
    9           NULL
    10          NULL
    11          NULL
    12          4
    13          4
    14          4
    15          6
    16          6
    17          6
    18          6
    19          6
    20          6
    21          6
    22          6
    23          6
    24          6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to append some JSON data from the last.fm API, I have been
Im trying to append some JSON data from the last.fm API, I have been
I have client application that uses WCF service to insert some data to backend
After some hours of trying, I want to ask how to loop a video
I have started to use Mustache JS some hours ago. I wonder if there
I was fighting with HighCharts quite some hours for formatting the data input to
I have asked a similar question about command line arguments in C++ some hours
i need some help with creating file Im trying in the last hours to
I have a table on which I want to perform some operations every hour.
From my iPhone app I insert some data in my sqlite database that include

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.