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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:09:03+00:00 2026-05-28T13:09:03+00:00

I’m trying to write a Microsoft SQL Server 2005 query that counts a total

  • 0

I’m trying to write a Microsoft SQL Server 2005 query that counts a total value, grouped by date with a cut-off point of 10:00am ?

eg: Table Orders

DateReceived              Total

01-01-2012 06:10:01       2       
01-01-2012 08:10:01       2   
01-01-2012 10:10:01       4   
02-01-2012 08:00:07       4   
02-01-2012 10:00:07       4  

I’d like to count the daily total, using 10:00 am as the cut-off point, so any orders before 10:00am appear in the total for the day before, and after 10:00 am in the total for that day.

I’m hoping to see query results like:

DateReceived              Total

31-12-2011                4       
01-01-2012                8   
02-01-2012                4  

I know how to group by just the date in Microsoft SQL Server:

SELECT DISTINCT CONVERT(varchar, [DateReceived], 111) AS [dt_DateReceived], 
SUM([Total]) AS perday
FROM         [Orders] 
GROUP BY CONVERT(varchar, [DateReceived], 111)
ORDER BY [DateReceived] DESC

However I am unsure how to add a cut off time of 10:00am using Microsoft SQL Server.

Using MySQL, I can achieve this by grouping on a subtracted interval, however am unsure how to translate this to SQL Server:

GROUP BY
  DATE(DATE_SUB( DateReceived , INTERVAL 10 HOUR))

Could anyone advise?

Thank you,
Jack

  • 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-28T13:09:03+00:00Added an answer on May 28, 2026 at 1:09 pm

    See the translation:

    SELECT 
      CONVERT(varchar, DATEADD(hour, -10, [DateReceived]), 111) AS [dt_DateReceived], 
      SUM([Total]) AS perday
    FROM [Orders] 
    GROUP BY CONVERT(varchar, DATEADD(hour, -10, [DateReceived]), 111)
    ORDER BY 1 DESC
    

    Test script

    Note that my local datetime format is yyyy-mm-dd

    ;WITH Orders AS (
        SELECT * FROM (VALUES
            (CAST('2012-01-01 06:10:01' AS DATETIME), 2)
            , ('2012-01-01 08:10:01', 2)
            , ('2012-01-01 10:10:01', 4)
            , ('2012-01-02 08:00:07', 4)
            , ('2012-01-02 10:00:07', 4)
        ) AS Orders (DateReceived, Total)       
    )
    SELECT  CONVERT(varchar, DATEADD(hour, -10, [DateReceived]), 111) AS [dt_DateReceived]
            , SUM([Total]) AS perday
    FROM    [Orders] 
    GROUP BY 
            CONVERT(varchar, DATEADD(hour, -10, [DateReceived]), 111)
    ORDER BY 
            1
    

    The testscript can be executed here

    PS: Distinction is not needed

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

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.