Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Grouping" Grouped results

Status
Not open for further replies.

Larshhh

IS-IT--Management
Jan 17, 2006
2
DK
I've been trying to make a query that would return the total cost of several sub-departments as one department. I can make Access return the sum of the individual departments (named 233, 23A, 241 and so on), but it returns the total cost of the individual sub-department (ex. 23A), and not the cost of the entire department (23*). Im using a wildcard in the department name as there are quite a few subdepartments, so hardcoding each department name would be quite troublesome, but I cant get access to group the results by the first two chars in the departmentname only.

The query looks something like this:
SELECT ["DEPARTMENT"], SUM(["COST"])
FROM 2004_TABLE
GROUP BY ["DEPARTMENT"]
HAVING ((["DEPARTMENT"]) Like "23*") OR ((["DEPARTMENT"]) Like "24*");

I hope you can help me with this.
 
A starting point:
SELECT Left(DEPARTMENT,2) As Dept, Sum(COST) As TotalCost
FROM 2004_TABLE
GROUP BY Left(DEPARTMENT,2)


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you for the help. It works just fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top