Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2005, 01:27 PM
Registered User
 
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default SubQuery totalling

I have created a monster!

The following (is not pretty but) produces a query successfully: I have inserted carriage returns to aid readability.

I now need to provide a report in access that has a Grand Total of the Total O/S column at the report footer, but am getting Group By errors.

Have tried to use DSum instead of a subquery in the SQL but cannot get this to work in place of the existing sub queries.

Can anyone spot any howling errors or make any suggestions. Will DSum be my answer? Am sorry if I have not explained too clearly but am tired after long day. If clarification needed please ask. Thank you.

SELECT
Analysis_owner.Manager,
quo.CCS_QUO_ANALYSIS_CODE AS AnaCode,
quo.[CCS_QUO_REF_NUMBER#1] AS RefNo1,
quo.[CCS_QUO_REF_NUMBER#2] AS RefNo2,
quo.[CCS_QUO_ADDRESS#1] AS Project,
quo.CCS_QUO_COST_YTD AS CostYTD,
quo.[CCS_QUO_COST_PRICE#6] AS Income,

(SELECT SUM(Nz(sil.[CCS_SIL_TOTAL],0)-Nz(sil.[CCS_SIL_VAT],0)) FROM CONSTRUCT_CCS_S_INVOICE_LINE sil WHERE quo.[CCS_QUO_QUOTE_NUMBER] = sil.[CCS_SIL_QUOTE_NUMBER] AND sil.[CCS_SIL_INV_MODE] Not Like '5' AND sil.[CCS_SIL_INV_MODE] Not Like '8' AND sil.[CCS_SIL_POSTED] <> 3) AS InvoiceExVAT,

(SELECT ROUND(SUM(trans.[ALLOCATED_AMOUNT])/1.175,2) FROM [ACCOUNTING_SYSTEM_SALES_TRANSACTIONS] trans, [CONSTRUCT_CCS_S_INVOICE_LINE] sil WHERE trans.[UNIQUE_REFERENCE_NO] =sil.[CCS_SIL_UNIQUE_REF_NO] AND quo.[CCS_QUO_QUOTE_NUMBER] =sil.[CCS_SIL_QUOTE_NUMBER]) AS ['Cash Recd'],

Round(Nz([InvoiceExVAT],0)-Nz(['Cash Recd'],0),2) AS ['Cash O/S'],
Round(Nz([ACCRUED_INC],0),2) AS ['Accrued Inc'],
Round(Nz([WIP],0),2) AS ['WIP'],
CCur((Nz(['Cash O/S'],0)+Nz(['Accrued Inc'],0)+Nz(['WIP'],0))) AS ['Total O/S']

FROM (CONSTRUCT_CCS_QUOTES AS quo INNER JOIN MONTHLY_PL ON quo.CCS_QUO_QUOTE_NUMBER=MONTHLY_PL.QUOTE_NUMBER) INNER JOIN Analysis_owner ON quo.CCS_QUO_ANALYSIS_CODE=Analysis_owner.Analysis_ code;








Similar Threads
Thread Thread Starter Forum Replies Last Post
Subquery debbiecoates SQL Server 2000 4 June 25th, 2008 03:49 AM
Subquery as table brettk_1 Oracle 1 January 22nd, 2007 02:10 PM
Do i have to use a subquery, if yes then how? code_lover SQL Language 2 January 2nd, 2007 02:22 PM
subquery khansa MySQL 1 February 21st, 2006 02:49 AM
Sub Totalling ppenn Excel VBA 3 April 22nd, 2004 11:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.