J
Jason
I am using Access to write reports for our SQL database using ODBC
connections. Currently I am working on a complex query to summarize
conference registration data that is stored in a single table, in individual
rows identified by the Person ID and Item ID.
To do this, I've setup subqueries to get the Person ID, Item Name and
Payment Amount for each Item ID. Then I have the query LEFT JOIN the full
conference registration list to each subquery on the PersonID, and populate
two fields with the data from the subqueries: One field has Item Names
(ActivityID) and the second is supposed to be the sum of the Payment Amounts
(AG_Current_Price).
It is working well when there is only one item to populate in each field.
But when there are multiple items, the sum function is not working. For
example, a person appears in both the CEU FEE subquery and the DONATIONS
subquery.
The CEU FEE subquery returns the result PersonID; CEU FEE ; 25
The DONATIONS subquery returns PersonID; DONATIONS ; 10
The aggregate result in the query should be: PersonID; CEU FEE
DONATIONS; 35
But instead I'm getting this result: PersonID; CEU FEE
DONATIONS; 2510
I cannot for the life of me figure out why the Sum function is not adding
the Payment Amounts, but I am getting a concatenated string instead. Any
ideas are appreciated.
Here's the SQL code:
SELECT dbo_AG_Person_MSTR.AG_Person_ID, [JAS Agora Conf Item -
CEU]![AG_ActivityID] & [JAS Agora Conf Item - Exhibitor]![AG_ActivityID] &
[JAS Agora Conf Item - Tables Fellows]![AG_ActivityID] & [JAS Agora Conf Item
- Exhibitor Commercial]![AG_ActivityID] & [JAS Agora Conf Item - CEU
Comp]![AG_ActivityID] & [JAS Agora Conf Item - Donation]![AG_ActivityID] AS
Expr1, Sum([JAS Agora Conf Item - CEU]![AG_Current_Price] & [JAS Agora Conf
Item - Exhibitor]![AG_Current_Price] & [JAS Agora Conf Item - Tables
Fellows]![AG_Current_Price] & [JAS Agora Conf Item - Exhibitor
Commercial]![AG_Current_Price] & [JAS Agora Conf Item - CEU
Comp]![AG_Current_Price] & [JAS Agora Conf Item -
Donation]![AG_Current_Price]) AS Expr2 INTO [JAS AG CRP3]
FROM ((((((dbo_AG_Person_MSTR INNER JOIN dbo_AG_EvtRegistrant_WORK ON
dbo_AG_Person_MSTR.AG_Person_ID = dbo_AG_EvtRegistrant_WORK.AG_Person_ID)
LEFT JOIN [JAS Agora Conf Item - CEU] ON dbo_AG_Person_MSTR.AG_Person_ID =
[JAS Agora Conf Item - CEU].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item -
Tables Fellows] ON dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item -
Tables Fellows].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item - Exhibitor] ON
dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item -
Exhibitor].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item - Exhibitor
Commercial] ON dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item -
Exhibitor Commercial].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item - CEU
Comp] ON dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item - CEU
Comp].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item - Donation] ON
dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item -
Donation].AG_Person_ID
GROUP BY dbo_AG_Person_MSTR.AG_Person_ID, [JAS Agora Conf Item -
CEU]![AG_ActivityID] & [JAS Agora Conf Item - Exhibitor]![AG_ActivityID] &
[JAS Agora Conf Item - Tables Fellows]![AG_ActivityID] & [JAS Agora Conf Item
- Exhibitor Commercial]![AG_ActivityID] & [JAS Agora Conf Item - CEU
Comp]![AG_ActivityID] & [JAS Agora Conf Item - Donation]![AG_ActivityID];
connections. Currently I am working on a complex query to summarize
conference registration data that is stored in a single table, in individual
rows identified by the Person ID and Item ID.
To do this, I've setup subqueries to get the Person ID, Item Name and
Payment Amount for each Item ID. Then I have the query LEFT JOIN the full
conference registration list to each subquery on the PersonID, and populate
two fields with the data from the subqueries: One field has Item Names
(ActivityID) and the second is supposed to be the sum of the Payment Amounts
(AG_Current_Price).
It is working well when there is only one item to populate in each field.
But when there are multiple items, the sum function is not working. For
example, a person appears in both the CEU FEE subquery and the DONATIONS
subquery.
The CEU FEE subquery returns the result PersonID; CEU FEE ; 25
The DONATIONS subquery returns PersonID; DONATIONS ; 10
The aggregate result in the query should be: PersonID; CEU FEE
DONATIONS; 35
But instead I'm getting this result: PersonID; CEU FEE
DONATIONS; 2510
I cannot for the life of me figure out why the Sum function is not adding
the Payment Amounts, but I am getting a concatenated string instead. Any
ideas are appreciated.
Here's the SQL code:
SELECT dbo_AG_Person_MSTR.AG_Person_ID, [JAS Agora Conf Item -
CEU]![AG_ActivityID] & [JAS Agora Conf Item - Exhibitor]![AG_ActivityID] &
[JAS Agora Conf Item - Tables Fellows]![AG_ActivityID] & [JAS Agora Conf Item
- Exhibitor Commercial]![AG_ActivityID] & [JAS Agora Conf Item - CEU
Comp]![AG_ActivityID] & [JAS Agora Conf Item - Donation]![AG_ActivityID] AS
Expr1, Sum([JAS Agora Conf Item - CEU]![AG_Current_Price] & [JAS Agora Conf
Item - Exhibitor]![AG_Current_Price] & [JAS Agora Conf Item - Tables
Fellows]![AG_Current_Price] & [JAS Agora Conf Item - Exhibitor
Commercial]![AG_Current_Price] & [JAS Agora Conf Item - CEU
Comp]![AG_Current_Price] & [JAS Agora Conf Item -
Donation]![AG_Current_Price]) AS Expr2 INTO [JAS AG CRP3]
FROM ((((((dbo_AG_Person_MSTR INNER JOIN dbo_AG_EvtRegistrant_WORK ON
dbo_AG_Person_MSTR.AG_Person_ID = dbo_AG_EvtRegistrant_WORK.AG_Person_ID)
LEFT JOIN [JAS Agora Conf Item - CEU] ON dbo_AG_Person_MSTR.AG_Person_ID =
[JAS Agora Conf Item - CEU].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item -
Tables Fellows] ON dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item -
Tables Fellows].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item - Exhibitor] ON
dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item -
Exhibitor].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item - Exhibitor
Commercial] ON dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item -
Exhibitor Commercial].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item - CEU
Comp] ON dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item - CEU
Comp].AG_Person_ID) LEFT JOIN [JAS Agora Conf Item - Donation] ON
dbo_AG_Person_MSTR.AG_Person_ID = [JAS Agora Conf Item -
Donation].AG_Person_ID
GROUP BY dbo_AG_Person_MSTR.AG_Person_ID, [JAS Agora Conf Item -
CEU]![AG_ActivityID] & [JAS Agora Conf Item - Exhibitor]![AG_ActivityID] &
[JAS Agora Conf Item - Tables Fellows]![AG_ActivityID] & [JAS Agora Conf Item
- Exhibitor Commercial]![AG_ActivityID] & [JAS Agora Conf Item - CEU
Comp]![AG_ActivityID] & [JAS Agora Conf Item - Donation]![AG_ActivityID];