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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:52:11+00:00 2026-06-16T01:52:11+00:00

I am beating my head against something that is, I’m sure, very obvious –

  • 0

I am beating my head against something that is, I’m sure, very obvious –

I have a bit of SQL code designed to sum the total selling price of each invoice in my store and then organize it by Month.

select SUM(totalsellingprice) from dbo.tblServiceOrders
where datepart(MONTH,dbo.tblServiceOrders.datereceived) =12

As far as I understand it, that should return the sum of all the totatlsellingprice from month 12 (December). Currently, this query returns

135998.92

However, if I then try to put that into a group by to get it to spit it out for all months, the number changes.

select SUM(totalsellingprice) from dbo.tblServiceOrders
group by datepart(MONTH,dbo.tblServiceOrders.datereceived)

And I get this table –

 1 - 110567.70
 2 - 60059.59
 3 - 135998.92
 4 - 63089.22
 5 - 102287.01
 6 - 71088.68
 7 - 149102.10
 8 - 67722.65
 9 - 67122.45
10 - 64234.82
11 - 7542.05
12 - 130461.10

There are 12 rows, which sounds good to me (12 months in a year) but the last row is 130461.

How is it possible that row 12 from the second search does not equal what I did in the first search? I feel like I’m missing something obvious but I can’t for the life of me figure out what.

Any and all help will be much appreciated!

  • 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-16T01:52:14+00:00Added an answer on June 16, 2026 at 1:52 am

    I got it:

    Your query is very confusing since it does not include the MONTH column:

    If you would have done that, you would have realized your query is not ordered by MONTH and so, the MONTH 12 is returned as the 3rd row of your query.

    😉

    select SUM(totalsellingprice) from dbo.tblServiceOrders
    group by datepart(MONTH,dbo.tblServiceOrders.datereceived)
    order by datepart(MONTH,dbo.tblServiceOrders.datereceived)
    

    And please, don’t refer to the row index to choose which month is related to which sum. And should be a good idea to also discriminate the year (if you need to).

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

Sidebar

Related Questions

I've been beating my head against this, and I'm sure I'm just missing something
I have to modify a VB6 app and am repeatedly beating my head against
I've been beating my head against this for awhile to no avail. I have
I am trying to implement something seemingly very simple, and I have been beating
I'm beating my head against the wall trying to figure this out. I have
So I have beating my head against the wall on this. I feel like
I'm nearly finished with this project but I have been beating my head against
I need some assistance and I'm beating my head against the wall. I have
OK, beating my head against the Javascript/jQuery wall over here, here is the code,
I have been beating my head against the desk for about a week. Hopefully

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.