473,387 Members | 1,572 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,387 software developers and data experts.

Trying to adjust Access query to enable obtaining monthly stats

20
I am a novice at SQL and am learning as I am going. Used below query to obtain the number of chargeable days visitors spent in various facilities during October. This query provides this information if no new visits for November have been entered in the database when the query is run. I need help with 'DateDiff('d',IIf([ADATE]>#11/1/2010#...'
When run recently it included the new November visit days in the query result, showing these days as negative days and subtracting them from the October total.

Also, since we want to run this query every month, how can I set it up to enable the query period to be manually entered, e.g. Between[Enter Start Date]...

Thanks for your help.


SELECT tblDemo.HRN, tblDemo.LastName, tblDemo.FirstName, tblHistory.ADATE, tblFACILITYTABLE.[Facility Name], tblHistory.DDATE, DateDiff('d',IIf([ADATE]<#10/1/2010#,#10/1/2010#,[ADATE]),IIf(Nz([DDATE],Date())>#10/31/2010#,#11/1/2010#,Nz([DDATE],Date()))) AS VisitDays
FROM tblFACILITYTABLE INNER JOIN (tblDemo INNER JOIN tblHistory ON tblDemo.NUM = tblHistory.NUM) ON tblFACILITYTABLE.LOC = tblHistory.LOC
GROUP BY tblDemo.NUM, tblDemo.LastName, tblDemo.FirstName, tblHistory.ADATE, tblFACILITYTABLE.[Facility Name], tblHistory.DDATE, DateDiff('d',IIf([ADATE]<#10/1/2010#,#10/1/2010#,[ADATE]),IIf(Nz([DDATE],Date())>#10/31/2010#,#11/1/2010#,Nz([DDATE],Date())))
HAVING (((tblHistory.ADATE)<=#10/31/2010#) AND ((tblHistory.DDATE)>=#10/1/2010#)) OR (((Nz([DDate],Date()))>=#10/1/2010#));


camgar
Nov 13 '10 #1
2 4214
orangeCat
83 64KB
Take a look here for some options:

http://office.microsoft.com/en-us/ac...001117077.aspx
Nov 14 '10 #2
cambar
20
This article, while informative, was not helpful. I already know how to structure basic queries with the types of parameters/criteria identified in the resource article.
Nov 14 '10 #3

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

Similar topics

2
by: Puneet Murgai | last post by:
I am trying to run an access query which works when I write it directly in the database. However, it fails when an SQL script containing it is run from C++. It doesn't recognize the Iff and Nz...
5
by: Art | last post by:
Hi, Can anyone point me to an example of how I would execute a query I've created in an Access DB. I've copied the SQL down to my VB.net application and that works fine, but it's ugly. I'd like...
8
by: s_wadhwa | last post by:
SELECT DISTINCTROW "01C" AS dummy, Buildings.BuildingNumber, UCASE(Buildings.BuildingName) AS BuildingName, Buildings.MasterPlanCode, Buildings.UniformBuildingCode,...
5
by: redstamp | last post by:
Try as I might I cannot find a way to write an access query to return a result set with the records from my database WITHOUT a certain set of values within a field. To explain, I have a table of...
3
by: Idlemind23 | last post by:
Ahoy! I'm hoping for some help on what (I believe) should be a simple task. I have a form with a button. I would like that button to have a caption with a date. That date should be pulled out...
8
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields...
1
by: newtechiebug | last post by:
I am trying to convert a MS Access Query to a SQL query and I need help with some IIF Statements? 2 in particular that I've encountered problems with are: Count(IIf(=0 Or...
3
by: =?Utf-8?B?bXNjZXJ0aWZpZWQ=?= | last post by:
Has anyone successfully used an Access query from .NET? I am trying to do this and am getting a weird error. .NET calls queries 'stored procedures'. The error I am getting says "Schema could not be...
2
by: k-man | last post by:
Hi: I have an MS Access query for a table called MyTable. One of my fields in the query is a custom field that looks like "MyField: = MyFunction(ID)" where ID is a field in MyTable. I have...
0
by: uno7031 | last post by:
Help Please!!! Adding 5 Days to another Date in an access query Good Morning, Help please…. I am new to access and trying to write a query that will add 5 days between a RecDate and a...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.