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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:04:22+00:00 2026-06-04T03:04:22+00:00

i am building some basic sql query and have come unstuck on a ‘group

  • 0

i am building some basic sql query and have come unstuck on a ‘group By’ clause. I have used alias on my column headers but have hit problems when trying to ‘group By’ my results. My code at the moment is:-

SELECT                 
  vwREP_GP_ContractProjectPurchaseCostCatID.PACOSTCATID AS COST_CAT_CODE, 
  vwREP_GP_ContractProjectPurchaseCostCatID.PACOSTCATNME AS COST_CAT_NAME, 
  vwREP_GP_ContractProjectPurchaseRpt.COST, 
  vwREP_GP_ContractProjectPurchaseRpt.ITEMDESC AS ITEM, 
  vwREP_GP_ContractProjectPurchaseRpt.CREDITOR, 
  vwREP_GP_ContractProjectPurchaseRpt.DOC_NUM AS DOCUMENT_NUMBER, 
  vwREP_GP_ContractProjectPurchaseRpt.DESCRIPTION, 
  vwREP_GP_ContractProjectPurchaseRpt.DOC_DATE AS DATE,  
  vwREP_GP_ContractProjectPurchaseRpt.PROJECT AS JOB_CODE_STAGE, 
  vwREP_GP_ContractProjectPurchaseRpt.COMPOUNDNAME AS CATEGORY_DESCRIPTION
FROM         
  vwREP_GP_ContractProjectPurchaseCostCatID 
INNER JOIN
  vwREP_GP_ContractProjectPurchaseRpt ON  wREP_GP_ContractProjectPurchaseCostCatID.PACOSTCATID = vwREP_GP_ContractProjectPurchaseRpt.PACOSTCATID


SELECT CATEGORY_DESCRIPTION, SUM(COST) AS TotalCost FROM 
    ( 
        SELECT COMPOUNDNAME AS CATEGORY_DESCRIPTION FROM wREP_GP_ContractProjectPurchaseRpt
    ) A 
GROUP BY CATEGORY_DESCRIPTION

Having added in extra code to deal with using alias column names I now get an error that ‘COST’ is an invalid column? I have not changed this column name??

I know its something obvious staring at me but my brain is not engaging so if anyone can point out where I am going wrong or a simplier way of doing this that would be a great help.

Thanks in advance.

(this is all being done on sql server management studio 2005)

  • 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-04T03:04:24+00:00Added an answer on June 4, 2026 at 3:04 am

    Use

    SELECT COMPOUNDNAME AS CATEGORY_DESCRIPTION, 
           Sum(COST) AS TotalCost 
    FROM   vwREP_GP_ContractProjectPurchaseRpt 
    GROUP  BY COMPOUNDNAME 
    

    instead of

    SELECT  CATEGORY_DESCRIPTION,SUM(COST)AS TotalCost FROM 
    ( 
        SELECT COMPOUNDNAME AS CATEGORY_DESCRIPTION FROM vwREP_GP_ContractProjectPurchaseRpt
    ) A 
    GROUP BY CATEGORY_DESCRIPTION
    

    You were not including the COST column in inner query.

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

Sidebar

Related Questions

I have a need to display some basic info about a facebook group on
I am building some basic HTML code for a CMS. One of the page-related
We're building some software for an in-house Kiosk. The software is a basic .net
The url shortening service I'm building needs to display some basic click stats to
I'm building a basic forum where every post contains some text, first and last
I'm trying to prevent some basic click-fraud on my site, and am building links
I'm building some AMIs from one of the basic ones on EC2. One of
i'm building some basic crud methods for my fluently mapped entities. i just wanna
I'm building a pretty basic table editor for an SQL Server DB in C#;
I'm new to opengl. As a learning exercise I started manually building some basic

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.