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 July 9th, 2008, 10:51 AM
Authorized User
Join Date: Feb 2007
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default trouble with subquery

I have the following qry:
SELECT tblDlr_Data.bkyr AS bookyr, Sum(tblDlr_Data.original_amtfin) AS original_amtfin, Sum(tblDlr_Data.EOM_ENR) AS EOM_ENR, (select sum([eom_enr]) from [tblDlr_Data] where [deldynb]="3" ) AS Expr1
FROM tblDlr_Data
GROUP BY tblDlr_Data.bkyr;

bkyr contains several rows (2003, 2004, 2005, etc).

Expr1 is bringing back the same total [eom_enr] where [deldynb] is equal to "3" in each row rather than grouping by bkyr. I've tried to us a "group by" within the subquery but that is not working. Any suggestions?

Old July 9th, 2008, 01:55 PM
Friend of Wrox
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

Avoid the subselect...it's not needed, it's a bad idea, and in any case it's not complex enough to get you the results you are after.

And why would you compare to "3" instead of just 3??? Is deldynb *really* a text field instead of a number field?

Try this:
SELECT bkyr AS bookyr, 
       Sum(original_amtfin) AS original_amtfin, 
       Sum(EOM_ENR) AS EOM_ENR, 
       Sum( IIF( deldynb=3, EOM_ENR, 0 ) ) AS whatever
FROM tblDlr_Data

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
SubQuery totalling alldis Access 0 February 22nd, 2005 01:27 PM

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