473,385 Members | 1,461 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Count two fields based on Date in a Query

58
I'm trying to Count data in a Query Combining two different fields based on the "Date" the product was sold, and for some reason I get a wrong data. When I use only this expression, It works fine:
Code:
Count(IIf([BDC Info Table].[Sold Date]>=#11/1/2008#,0)) AS [CountNovSold]

But when I want to Count another field based on the same Date.
Code:
Count(IIf([BDC Info Table].[Status]="Sold Not Set",0) And (IIf([BDC Info Table].[Sold Date]>=#11/1/2008#,0))) AS [CountOfSold Not Set]


It gives me a wrong data. Apparently, It doesn't recognize the exact Date.
Any Help would be greatly appreciated

plaguna
Nov 10 '08 #1
3 2283
puppydogbuddy
1,923 Expert 1GB
Try it this way:

Expand|Select|Wrap|Line Numbers
  1. (Count(IIf([BDC Info Table].[Status]="Sold Not Set",0)) + Count(IIf([BDC Info Table].[Sold Date]>=#11/1/2008#,0))) AS [CountOfSold Not Set]
Nov 11 '08 #2
plaguna
58
Actually I want to retrieve [Status ]=“Sold not Set” when [Sold Date] is >=11/01/2008.
I found that Count will count all non-null values. That’s why I didn’t get the right data.
What do you think about this expression.
Code:

Expand|Select|Wrap|Line Numbers
  1. Abs(Sum([BDC Info Table].[Status]="Sold Not Set" And [BDC Info Table].[Sold Date]<#11/1/2008#)) AS [CountOfSold Not Set]
plaguna
Nov 17 '08 #3
puppydogbuddy
1,923 Expert 1GB
Actually I want to retrieve [Status ]=“Sold not Set” when [Sold Date] is >=11/01/2008.
I found that Count will count all non-null values. That’s why I didn’t get the right data.
What do you think about this expression.
Code:

Expand|Select|Wrap|Line Numbers
  1. Abs(Sum([BDC Info Table].[Status]="Sold Not Set" And [BDC Info Table].[Sold Date]<#11/1/2008#)) AS [CountOfSold Not Set]
plaguna
Does your expression work for you? Also, in regards to your statement count not including null values, you should be aware that Count(*) counts null and non-null values. Count([SomeField]) will only count non-null values.

If your expression above does not work, you can try this variation of the one I gave you previously that utilizes the null to zero function, which should convert your nulls to zeros in the count and give you the answer you are looking for.

Expand|Select|Wrap|Line Numbers
  1. nz(Count(IIf([BDC Info Table].[Status]="Sold Not Set",0)),0) + nz(Count(IIf([BDC Info Table].[Sold Date]>=#11/1/2008#,0))),0) AS [CountOfSold Not Set]
Nov 18 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: G | last post by:
I need to be able to count accounts as they are entered by operators. Each account number has fields such as "Statements req date" and "Application req date". I would like the database to count...
7
by: Hugo L. | last post by:
Dear I have a table with a Text field named "Attest". In that field I can fill in 4 possibilities: A, B, C or D. In a report based om that table I want to count how many times I filled in...
2
by: Cro | last post by:
Dear Access Developers, I am developing a form with 'default view' set to "continuous forms". I am suffering with a problem I can't yet see a solution too. Each record has many fields. Two...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
7
by: Jerome | last post by:
Hallo, I know a lot has already been told about date/time fields in a database but still confuses me, specif when dealing with SQLserver(Express). It seems that sqlserver only accepts the date in...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
2
by: jennwilson | last post by:
I am trying to generate a report based on a query that will list any records where an individual has a date listed that matches the specified time for one or both of the date fields. The two fields...
2
by: tak786 | last post by:
hello.. i have created query which has 1 "date field" which I need to count the instances of each month. i.e field 1: date field = count of "*01/2007" field 2: date field = count of...
6
by: BeaBea | last post by:
Hi All, I am trying to set up a report based on a Select Query. I need to do a count based on four different fields. Field 1: Product Type (text field - 5 different products) Field 2: Claim...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.