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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:13:18+00:00 2026-06-08T20:13:18+00:00

i would like to compute the data from a table where it consists date,

  • 0

i would like to compute the data from a table where it consists date, hour and data ..there are a lot of data inside the table.. the hour is int datatype in the database and other (DATE.etc) are datatype varchar.. the example are as below:

DATE       hour  data1  data2
-------------------------------
01/01/2010  1    10860  1234    
01/01/2010  2    10861  1234    
01/01/2010  3    10862  1234    
01/01/2010  4    10863  567   
01/01/2010  5    10864  458    
02/01/2010  1    10865  3467    
02/01/2010  2    10866  7890    
02/01/2010  3    10867  863    
02/01/2010  4    10868  0    
02/01/2010  5    10868  698  
03/01/2010  1    10868  4693  
03/01/2010  2    10868  7853  
03/01/2010  3    10868  5987
....................etc

and from above data. i would like to sum the data from date: 01/01/2010, hour: 2 to the next day date:02/01/2010, hour:1 and of course date:02/01/2010, hour:2 to date:03/01/2010, hour:1 and the rest of the data .. meaning that the output of the data result would be as below:

DATE           sdata1  sdata2
-------------------------------
01/01/2010     54315   6960    
02/01/2010     54337   14144    
03/01/2010     21736   13840
...................etc

the datatype for date, data1 and data2 are varchar EXCEPT time is datatype int…

the sdata1 and sdata2 are the sum of the data and is there any other way that may sum up those data in condition from today hour:2 to the next day hour:2 ? thank you so much everyone ..thank you ..

those data are resulted from bulk insert of PLC data…

here is my own solution but it never work out!!

select SUM(CONVERT(int,data1)) AS sdata1,SUM(CONVERT(int,data2)) AS sdata2 from table where
(CONVERT(datetime, date, 105) >= CONVERT(datetime,date,105) and CONVERT(int,hour) >= 2) and
(CONVERT(datetime, date, 105) <= DATEADD(day, 1,CONVERT(datetime,date,105)) and CONVERT(int,hour) < 2)
and
month(CONVERT(datetime,Date,103))= ’01’ and year(CONVERT(datetime,Date,103))= ‘2010’

someone help me figure this out please … my brain is burst … @@

  • 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-08T20:13:20+00:00Added an answer on June 8, 2026 at 8:13 pm

    Here you go

    set dateformat dmy
    declare @t table(DATE  date,     hour int,  data1  int, data2 int)
    insert into @t
    select '01/01/2010',  1,    10860,  1234     union all
    select '01/01/2010',  2,    10861,  1234     union all
    select '01/01/2010',  3,    10862,  1234     union all
    select '01/01/2010',  4,    10863,  567    union all
    select '01/01/2010',  5,    10864,  458     union all
    select '02/01/2010',  1,    10865,  3467     union all
    select '02/01/2010',  2,    10866,  7890     union all
    select '02/01/2010',  3,    10867,  863     union all
    select '02/01/2010',  4,    10868,  0     union all
    select '02/01/2010',  5,    10868,  698   union all
    select '03/01/2010',  1,    10868,  4693   union all
    select '03/01/2010',  2,    10868,  7853   union all
    select '03/01/2010',  3,    10868,  5987 
    
    select dateadd(day,case when hour>1 then 1 else 0 end,date),
    sum(data1),sum(data2) 
    from @t
    group by dateadd(day,case when hour>1 then 1 else 0 end,date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like to compute the data from a table where it consists date,
I have data that I would like to compute some statistics with. The data
I would like to use a Groovy closure to process data coming from a
I would like to import some basic data (only few integers) from an Excel
For given floating point numbers x and a , I would like to compute
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I need to export data from a SQL database (some groups use SQL Server,
I have database application on Android device. I would like to have a possibility
I would like to change the database files location of MySQL administrator to another
i would like to play with the constructing calls feature of gcc... From the

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.