MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 12th, 2012, 10:11 AM
stinkyjak stinkyjak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 8 stinkyjak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 22 sec
Reputation Power: 0
Query repeat int_value for each hour until int_value changed

ID:1 Int_Value:23 timestamp:1349961140622
ID:2 Int_Value:34 timestamp:1350035047861
ID:3 Int_Value:12 timestamp:1350043447929

I need two things. First I need to know how to turn timestamp into date/time and then into hours.

Most importantly, I need to know how to produce a row in the result for each hour and have the Int_Value repeated for each hour until the the hour equal to the next time stamp has a different Int_value... then repeat until Int_Value changes again for the date range given.

I have no idea how to do this using SQL. Please help. Result would look like. (of course the timestamps above don't equal the example hours below)

ID Value Hour
1 23 01
2 23 02
3 23 03
4 23 04
5 34 05
6 34 06
7 34 07
8 34 08
9 34 09
10 12 10
11 12 11
12 12 12
13 12 13

Any help or references is greatly appreciated. Thank you for your time.

Note: This timestamp is a bigint and it is representing a Java time stamp...

Reply With Quote
  #2  
Old October 16th, 2012, 10:30 AM
stinkyjak stinkyjak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 8 stinkyjak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 22 sec
Reputation Power: 0
The timestamp is actuall unix time so this is taken care of with

DATEADD() function to figure out the timestamp.
Usage:

SELECT DATEADD(s,t_stamp/1000,'1970-01-01 00:00:00') FROM sqlth_data...

Reply With Quote
  #3  
Old October 16th, 2012, 01:16 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,369 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 19 m 34 sec
Reputation Power: 4140
oh shoot, that's it! divide by a thousand!

your numbers looked familiar, but i saw them as way too big to be unix times

thanks for posting and updating the solution

Comments on this post
stinkyjak agrees!
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #4  
Old October 16th, 2012, 02:16 PM
stinkyjak stinkyjak is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 8 stinkyjak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 22 sec
Reputation Power: 0
Quote:
Originally Posted by r937
thanks for posting and updating the solution



But what I need is still unknown. I am sure it is easy....

How to I get the repeat or cloak of the same number for every iteration until the int_value changes. A record is only recorded when a value changes. I am trying to produce a result that has a value for ever time iteration. Most would not actually have a record in the db for that time, unless the int_value had changed at that time.

Reply With Quote
  #5  
Old October 16th, 2012, 04:39 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,369 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 19 m 34 sec
Reputation Power: 4140
Quote:
Originally Posted by stinkyjak
I am trying to produce a result that has a value for ever time iteration.
i understand this

what you need is a LEFT OUTER JOIN where the time iterations are the left table, and your data is the right table, and for each time iteration, there may or may not be a data row

correct?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Query repeat int_value for each hour until int_value changed

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap