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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:08:42+00:00 2026-06-06T15:08:42+00:00

I am pulling through some data in SQL Server and I would like to

  • 0

I am pulling through some data in SQL Server and I would like to GROUP BY my results but cannot get it to work.

This is my current SQL statement:

SELECT
   PA01201.CUSTNMBR, 
   PA01201.PACONTNUMBER, 
   PA01201.PAcontid, 
   PA01100.CUSTNMBR AS Expr1, 
   PA01100.PAcontname, 
   PA01100.PAcontid AS Expr2, 
   PA01100.PACONTNUMBER AS Expr3, 
   PA01201.PAprojname, 
   PA01201.PAPROJNUMBER
   PA01201.Cost

FROM        
   PA01201 
INNER JOIN
   PA01100 ON PA01201.CUSTNMBR = PA01100.CUSTNMBR AND 
              PA01201.PACONTNUMBER = PA01100.PACONTNUMBER AND 
              PA01201.PAcontid = PA01100.PAcontid 

It returns these results:

CUSTNMBR    PACONTNUMBER    PAcontid    Expr1   Pacontname  Expr2   Expr3   Paprojname  PAPROJNUMBER    Cost
AD001           8051    8051    AD001           Company 1   8051    8051    Project 1   08051P          951
AP001           8063    8063    AP001           Company 2   8063    8063    Project 2   08063P          2651
AR002           8096    8096    AR002           Company 3   8096    8096    Project 3   08096P          807
AR003           9033    9033    AR003           Company 4   9033    9033    Project 4   09033P          458
AS001           8013    8013    AS001           Company 5   8013    8013    Project 5   08013C          3297
AS001           8013    8013    AS001           Company 5   8013    8013    Project 5   08013P          48
AS001           8013    8013    AS001           Company 5   8013    8013    Project 5   08013P          641
AR002           8096    8096    AR002           Company 3   8096    8096    Project 3   08096P          1000

I would like to be able to group the result by PAcontid.

Can anyone advise the easiest way to do this?

When I try and insert a GROUP BY clause I get an error stating that the other columns (CUSTNMBR, PAPROJNUMBER) etc are not included in the clause????

Any help much appreciated.

All work is being done in SQL Server Management Studio 2008 R2


Sorry for some reason my last column (Cost) didn;t come through. I have updated my question to show the proper fields. Basically what I am trying to do is get a total cost for each Pacontid.

I would like my results to look something like ……..

CUSTNMBR    PACONTNUMBER    PAcontid    Expr1   Pacontname  Expr2   Expr3   Paprojname  PAPROJNUMBER    Cost
    AS001           8013    8013    AS001           Company 5   8013    8013    Project 5   08013P          3986
    AD001           8051    8051    AD001           Company 1   8051    8051    Project 1   08051P          951
    AP001           8063    8063    AP001           Company 2   8063    8063    Project 2   08063P          2651
    AR002           8096    8096    AR002           Company 3   8096    8096    Project 3   08096P          1807
    AR003           9033    9033    AR003           Company 4   9033    9033    Project 4   09033P          458

Is this possible in what I am trying to do?

  • 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-06T15:08:43+00:00Added an answer on June 6, 2026 at 3:08 pm

    When using GROUP BY, all the selected columns must be in the GROUP BY clause or, if not, an aggregate function (ex: SUM, MAX, MIN, AVG) around it!

    For more info, check THIS.


    In you case, a possible solution might be:

    SELECT  MAX(PA01201.CUSTNMBR),
            MAX(PA01201.PACONTNUMBER),
            PA01201.PAcontid,
            MAX(PA01100.CUSTNMBR AS Expr1,
            MAX(PA01100.PAcontname),
            MAX(PA01100.PAcontid) AS Expr2,
            MAX(PA01100.PACONTNUMBER) AS Expr3,
            MAX(PA01201.PAprojname),
            MAX(PA01201.PAPROJNUMBER)
    FROM       PA01201
    INNER JOIN PA01100 ON PA01201.CUSTNMBR = PA01100.CUSTNMBR
           AND PA01201.PACONTNUMBER = PA01100.PACONTNUMBER
           AND PA01201.PAcontid = PA01100.PAcontid
    GROUP BY PA01201.PAcontid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is something I need to accomplish: WPF datagrid display/bind data from SQL through
I am trying to perform some computations on a server. For this, the client
I am pulling back some data from the twitter query API, and parsing it
Pulling my hair out over this one. I have one wordpress install at /2009
I am pulling data from one table, called analyzedCopy, and using it to over-rite
I am pulling my hair out on this one... I am using the ASIHTTPRequest
I have been pulling my hair out about this since Friday and I am
I am pulling back a large amount of tabular data that I wish to
I'm pulling in xml using the cocoa NSXmlParser. Since this process most likely won't
This goes back to my other question which I thought was sufficiently answers but

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.