PC Review


Reply
 
 
JustinP
Guest
Posts: n/a
 
      8th Sep 2006
I need to make a query for a report that includes a number of count and
count-like statements.

As an example (there are about 20 other statements like this example in
the query):

SELECT
Abs(Sum((IIf(MasterTable.SECTION_NAME="BCab",1,0)) And
(IIf(MasterTable.Private_Gov="PRIVATE",1,0)) And
(IIf(MasterTable.REDUNDANT=No,1,0)))) AS CountOfPrivOwn
FROM MasterTable;

but I also need to include this (and several like this with other
criteria):

SELECT Count(*) FROM
(SELECT DISTINCT Owner FROM Mastertable);


Is it possible to include both of these types of statements in the one
query? (I want this in one query for convience more than anything. Is
it possible to programmatically call data from another query in Access?
This may be an option.)

I am aware I could use a UNION in between them but as this would put
the second type of statement on another line could this data then be
automatically taken into the report?

Are there any other ways around this? Your suggestions are most welcome.

 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      8th Sep 2006
What, in English, are you expecting

SELECT
Abs(Sum((IIf(MasterTable.SECTION_NAME="BCab",1,0)) And
(IIf(MasterTable.Private_Gov="PRIVATE",1,0)) And
(IIf(MasterTable.REDUNDANT=No,1,0)))) AS CountOfPrivOwn
FROM MasterTable;

to be doing?

Assuming you want to count all those records where SECTION_NAME = BCab AND
Private_Got = PRIVATE AND Redundant = No, you'd be best off ANDing the
conditions together, not the results of the individual IIf statements:

SELECT
Abs(Sum((IIf(MasterTable.SECTION_NAME="BCab" And
(MasterTable.Private_Gov="PRIVATE" And MasterTable.REDUNDANT=No,1,0))) AS
CountOfPrivOwn
FROM MasterTable;

What I've often done when I needed to UNION various counting queries
together was then do a SUM query on the resultant query.

In other words, I might have Query1 as

SELECT Sum(Field1) AS Result1, 0 AS Result2
FROM Table1
UNION
SELECT 0, Sum(Field2)
FROM Table2

and then

SELECT Sum(Result1) AS FirstSum, Sum(Result2) AS SecondSum
FROM Query1

so that everything appears as a single row.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"JustinP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I need to make a query for a report that includes a number of count and
> count-like statements.
>
> As an example (there are about 20 other statements like this example in
> the query):
>
> SELECT
> Abs(Sum((IIf(MasterTable.SECTION_NAME="BCab",1,0)) And
> (IIf(MasterTable.Private_Gov="PRIVATE",1,0)) And
> (IIf(MasterTable.REDUNDANT=No,1,0)))) AS CountOfPrivOwn
> FROM MasterTable;
>
> but I also need to include this (and several like this with other
> criteria):
>
> SELECT Count(*) FROM
> (SELECT DISTINCT Owner FROM Mastertable);
>
>
> Is it possible to include both of these types of statements in the one
> query? (I want this in one query for convience more than anything. Is
> it possible to programmatically call data from another query in Access?
> This may be an option.)
>
> I am aware I could use a UNION in between them but as this would put
> the second type of statement on another line could this data then be
> automatically taken into the report?
>
> Are there any other ways around this? Your suggestions are most welcome.
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help..Simple, compound, complex, compound-complex examples Peggylynne Microsoft Word Document Management 1 30th May 2010 07:22 AM
complex color fill conditions- if statements or complex formula? lilly8008 Microsoft Excel Misc 1 18th Dec 2009 04:57 AM
Complex Index Match Help (or at least complex to me) Jennifer Reitman Microsoft Excel Misc 3 10th Aug 2006 08:51 PM
Using toggle buttons in a complex query (complex for me, at least) =?Utf-8?B?QmlsbHk=?= Microsoft Access Forms 4 23rd Jun 2005 02:08 AM
Help!!! how to make a complex form for input? (at least I think it is complex...) tsangwi Microsoft Access Forms 0 22nd Nov 2003 02:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:18 PM.