473,378 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Subquery Help Needed

I'm new to this group and not an experienced Access user, but have solved several of my problems already by reading other threads on this forum (Thanks!). Here's my current problem that I can't figure out how to solve:

I'm trying to calculate total project management budget by project phase. I have a query that returns data grouped by project and index code, and has the sum of the PM budgets along with a field called 'WBS_CONCAT_Name'. This name field specifies which phase of the project the budget belongs to (Design, Construction, Bid & Award, etc.). I now need to group and sum by that concatenated name field in order to get the PM budget by phase. Here's the query that extracts the project management budget:

SELECT ADMUSER_PUC_PROJ_MONTHLY_REPORT.PROJ_ID, ADMUSER_PUC_PROJ_MONTHLY_REPORT.PROJ_SHORT_NAME, ADMUSER_PUC_PROJ_MONTHLY_REPORT.PROJ_NAME, ADMUSER_PUC_WBS_BUDGETED_COSTS.WBS_CONCAT_NAME, Sum(ADMUSER_PUC_WBS_BUDGETED_COSTS.ORIG_BUDGETED_C OST) AS [PM Budget]
FROM ADMUSER_PUC_PROJ_MONTHLY_REPORT INNER JOIN ADMUSER_PUC_WBS_BUDGETED_COSTS ON ADMUSER_PUC_PROJ_MONTHLY_REPORT.PROJ_ID = ADMUSER_PUC_WBS_BUDGETED_COSTS.PROJ_ID
WHERE (((ADMUSER_PUC_WBS_BUDGETED_COSTS.WBS_NAME)="Proje ct Management"))
GROUP BY ADMUSER_PUC_PROJ_MONTHLY_REPORT.PROJ_ID, ADMUSER_PUC_PROJ_MONTHLY_REPORT.PROJ_SHORT_NAME, ADMUSER_PUC_PROJ_MONTHLY_REPORT.PROJ_NAME, ADMUSER_PUC_WBS_BUDGETED_COSTS.WBS_CONCAT_NAME;

The data in the field 'WBS_CONCAT_NAME' looks like this:
CUW37801.BA.PM
CUW37801.CL.PM
CUW37801.CM.PM
CUW37801.DS.PM
CUW37801.ER.PM
CUW37801.PL.PM
CUW37901.BA.PM
CUW37901.CL.PM
CUW37901.CM.PM
CUW37901.DS.PM
CUW37901.ER.PM
CUW37901.PL.PM
CUW37201.BA.PM

I'm trying to write a subquery that looks at this string and sums all the budgets where the string contains 'BA' into a total called Bid&AwardPMBudget, CL into closeout budget, etc. Here's what I tried:

SELECT [B - P3e PM Budgets].PROJ_ID, [B - P3e PM Budgets].PROJ_SHORT_NAME, [B - P3e PM Budgets].PROJ_NAME, Sum((SELECT [PM Budget] FROM [B - P3e PM Budgets] WHERE ((([B - P3e PM Budgets].WBS_CONCAT_NAME) Like '*DS*')))) AS [PM Budget]
FROM [B - P3e PM Budgets]
GROUP BY [B - P3e PM Budgets].PROJ_ID, [B - P3e PM Budgets].PROJ_SHORT_NAME, [B - P3e PM Budgets].PROJ_NAME;

I get a message saying this query can return only one record.

I think my problem is that I can't just use a subquery and instead need to make a temp table? I have no idea if that will work or how to do it, and I also have no idea if there's a way to do this in the initial query. I didn't find info in help, or on the Microsoft website and would appreciate any advice. Thanks.
Nov 1 '06 #1
2 1457
MMcCarthy
14,534 Expert Mod 8TB
Try something like this:

SELECT Sum(IIf([B - P3e PM Budgets].[WBS_CONCAT_NAME] Like '*BA*',[B - P3e PM Budgets].[PM Budget],0)) As Bid&AwardPMBudget,
Sum(IIf([B - P3e PM Budgets].[WBS_CONCAT_NAME] Like '*CL*',[B - P3e PM Budgets].[PM Budget],0)) As CloseoutBudget
FROM [B - P3e PM Budgets];

When you include other fields in your query the sum total you are trying to achieve is being broken down by those fields.
Nov 1 '06 #2
Try something like this:

SELECT Sum(IIf([B - P3e PM Budgets].[WBS_CONCAT_NAME] Like '*BA*',[B - P3e PM Budgets].[PM Budget],0)) As Bid&AwardPMBudget,
Sum(IIf([B - P3e PM Budgets].[WBS_CONCAT_NAME] Like '*CL*',[B - P3e PM Budgets].[PM Budget],0)) As CloseoutBudget
FROM [B - P3e PM Budgets];

When you include other fields in your query the sum total you are trying to achieve is being broken down by those fields.
THANK YOU!!!! I didn't even think of trying IIF but it worked perfectly.
Nov 1 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: lev | last post by:
CREATE TABLE . ( NULL , , (44) ) ID is non-unique. I want to select all IDs where the last entry for that ID is of type 11.
7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
0
by: Greg Stark | last post by:
Postgresql 7.4b2 (approximately, compiled out of CVS) When I have a subquery that has a complex subquery as one of the result columns, and then that result column is used multiple times in the...
8
by: Venkata C | last post by:
Hi! Does anyone here know of a way to goad DB2 into converting a correlated subquery to a non-correlated one? Does DB2 ever do such a conversion? We have a query of the form SELECT .. FROM A...
5
by: Mike MacSween | last post by:
This as the row source for a combo: SELECT qryRole.RoleID, qryRole.Role FROM qryRole WHERE (((qryRole.RoleID) Not In (SELECT RoleID FROM qryRoleEvent INNER JOIN qryEvent ON qryRoleEvent.EventID...
2
by: Hexman | last post by:
Don't know if this is the proper newsgroup to post to. Sorry if not. Can't figure this one out. Using Access 2003. I have 2 tables, IMast (table of part info) and THist (part transaction...
2
by: BerkshireGuy | last post by:
tblDetails has the following fields: AgencyCode, ProducerCode, AnnualPX How can I create a query to show the Top 5 producers with the highest PX per agency? Can a subquery do it? TIA
5
by: Anne | last post by:
Hello! Here is the statement in question: --STATEMENT A SELECT * FROM dbo.myTable WHERE colX in (SELECT colX FROM dbo.sourceTable) The problem with Statement A is that 'colX' does not exist...
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.