Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count records between start and end dates !

Status
Not open for further replies.

specialist

Programmer
Sep 7, 2001
50
US
greetings-

I am trying to run a query which will count the number of records in a table but just cannot seem to get it working!

The background is this:

If a record is active, it has a 'Status' of '1', if it is pending, it has a status of '2'. What I am trying to acomplish is to get a count of all records which were active between a set time (StartDate and EndDate values from a form). For example, for historical analysis we would like to see the number of records that were open at the end of the quarter. So I would want to count all records with a status of either 1 or 2. The query I have below does not seem to capture any historical data. I tried to check all in year 2003 and returned the wrong value. My goal is to always display the records which were active during the date values.

If anyone could please check the query below and give me any advice I would GREATLY appreciate it.

Thank you for reading this post and for any assistance.

-Mike

------------------------------------------------------------
SELECT Count ('Entry') as prnRecs FROM tbl_Info

Set qryOffice4 = db.Execute(qryPri & "WHERE Category = 2 AND Status = 1 AND Location = ('Office') AND Initial_Date <= '" & EndDate & "' AND Complete = 1 OR Category = 2 AND Status = 2 AND Location = ('Office') AND Initial_Date <= '" & EndDate & "' AND Complete = 1 AND Category = 2 AND Status = 2 AND Location = ('Office') AND Close_Date >= '" & EndDate & "' AND Complete = 1 OR Category = 2 AND Status = 1 AND Location = ('Office') AND Close_Date >= '" & EndDate & "' AND Complete = 1")
 
If you print out the result of string concatenation and format it nicely, I'll take a look at it.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top