Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
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 September 19th, 2003, 02:39 PM
Registered User
 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default count records where condition not true (IIF??)

hi all

how do i use 'count' to return instances where the condition does not occur? (count is zero)???

for example, here's the table (TAB1):

Player Home Away
Jim 10 27
Jim 12 13
Ron 10 7
Ron 52 10
Ron 3 17
Dave 17 10
Dave 0 7

for each distinct Player, i want to know how many records have Home>Away, *even if that number is zero*

so in this example, i want to get back:

Player Wins
Jim 0
Ron 2
Dave 1

i tried this:
select distinct Player, IIF(count(*) is null, 0, count(*))
from TAB1
where Home > Away
group by Player
order by Player

but it still doesnt count Jim's zero wins.

thx!
rudi



 
Old September 19th, 2003, 03:30 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is this for a report?
 
Old September 19th, 2003, 03:34 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Doesn't matter. This will show wins & losses. You can delete the losses column if you wish.

SELECT TAB1.Name, Sum(IIf([Home]>[away],1,"0")) AS Wins, Sum(IIf([Home]<[away],1,"0")) AS Losses
FROM TAB1
GROUP BY TAB1.Name
ORDER BY Sum(IIf([Home]>[away],1,"0"))
WITH OWNERACCESS OPTION;

Regards,

Beth M
 
Old September 19th, 2003, 03:36 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, change TAB1.Name to TAB1.Player in all instances. It should read:

SELECT TAB1.Player, Sum(IIf([Home]>[away],1,"0")) AS Wins, Sum(IIf([Home]<[away],1,"0")) AS Losses
FROM TAB1
GROUP BY TAB1.Player
ORDER BY Sum(IIf([Home]>[away],1,"0"))
WITH OWNERACCESS OPTION;

Beth M





Similar Threads
Thread Thread Starter Forum Replies Last Post
Count nodes based of if condition suri_1811 XSLT 1 December 7th, 2006 08:00 PM
IIF Condition Issue bufanator Access 2 September 11th, 2006 09:44 AM
Filtering records using iif statement Anlon Access 2 April 21st, 2005 01:24 PM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
Condition before insert the records mateenmohd SQL Server 2000 0 February 7th, 2005 09:13 AM





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