Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 19th, 2003, 02:39 PM
Registered User
 
Join Date: Sep 2003
Location: , , .
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



Reply With Quote
  #2 (permalink)  
Old September 19th, 2003, 03:30 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: Houston, Texas, USA.
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is this for a report?
Reply With Quote
  #3 (permalink)  
Old September 19th, 2003, 03:34 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: Houston, Texas, USA.
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
Reply With Quote
  #4 (permalink)  
Old September 19th, 2003, 03:36 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: Houston, Texas, USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:05 AM.


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