Database consists of records of visitors who have stayed at various contracted locations. Have ADATE and DDATE. Need to isolate all those who have stayed any days in October. So, in some cases they may have begun their stay in September and left during October or they may have begun their stay in October and not yet left. I further, need to be able to count the number of days each visitor has stayed during October.
I cannot seem to get what I need. I have specified ADATE Between 10/01/2010 And 10/31/2010 or DDATE Between 10/01/2010 and 10/31/2010 and have done DateDiff to get days. However, DateDiff is including all days in the count, not just those in October and is not counting October days at all for those visitors who have not departed yet. Can you please help me with how to structure this query?
Thanks so much
cambar
OK. Adding one is pretty simple I would guess, but : Cambar:
it will not provide the number of October days
doesn't tell me what it does do. Does it give an error? Zero maybe?
Anyway, try this for now : - SELECT *
-
, DateDiff('d',
-
IIf([ADate] < #10/1/2010#, #10/1/2010#, [ADate]),
-
IIf(Nz([DDate], Date()) > #10/30/2010#, #10/30/2010#, Nz([DDate], Date()))) + 1 AS OctDays
-
FROM [Table]
-
WHERE ([ADate] <= #10/30/2010#)
-
AND (Nz([DDate], Date()) >= #10/1/2010#)
5 2084 NeoPa 32,556
Expert Mod 16PB
You probably want to look at something with a structure similar to : - SELECT *
-
, DateDiff('d',
-
IIf([ADate] < #10/1/2010#, #10/1/2010#, [ADate]),
-
IIf([DDate] > #10/30/2010#, #10/30/2010#, [DDate])) AS OctDays
-
FROM [Table]
-
WHERE ([ADate]<=#10/30/2010#)
-
AND ([DDate]>=#10/1/2010#)
NeoPa response does not count October days if there is no DDATE. If the visitor arrived in late October and has not yet departed, it will not provide the number of October days. And if the visitor arrived and left the same day, the day count is 0 when it needs to be 1.
NeoPa 32,556
Expert Mod 16PB
OK. Adding one is pretty simple I would guess, but : Cambar:
it will not provide the number of October days
doesn't tell me what it does do. Does it give an error? Zero maybe?
Anyway, try this for now : - SELECT *
-
, DateDiff('d',
-
IIf([ADate] < #10/1/2010#, #10/1/2010#, [ADate]),
-
IIf(Nz([DDate], Date()) > #10/30/2010#, #10/30/2010#, Nz([DDate], Date()))) + 1 AS OctDays
-
FROM [Table]
-
WHERE ([ADate] <= #10/30/2010#)
-
AND (Nz([DDate], Date()) >= #10/1/2010#)
Thank you very much for your help. This works.
camgar
NeoPa 32,556
Expert Mod 16PB
I'm pleased that was helpful Cambar :-)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: JT |
last post by:
Hello all, I've been using sql and mysql in particular for several
years now, but I'm having some trouble coming up with a query that
will pull the data that I need from a mysql table without using...
|
by: Mike N. |
last post by:
Hello to all:
First let me apologize for the length of this question, I've made an attempt
to include as much information as is needed to help with the question.
I am having problems putting...
|
by: Adam Nemitoff |
last post by:
I have two tables populated during the use of an application to log
user events and application states. They are named "EventTable" and
"StateTable" and the structures follow:
EventTable:
ID...
|
by: MLH |
last post by:
I apologize in advance to forum readers noticing this somewhat
redundant post. I fear that my Subject Heading was ill-chosen in
earlier post I made on this topic. Am hoping that a clearer Subject...
|
by: Norma |
last post by:
I am trying to make a query pull data from between the dates I enter
in the parameter but also look back 'in time' to see where 2 other
fields have null values, and only pull data into the query if...
|
by: JellyMan |
last post by:
I am trying to do something with an Access SQL query that I have never
done. I can see how it SHOULD work in my head, but can't seem to make
it work in reality. I think I have it close, but my SQL...
|
by: Luqman |
last post by:
I have created a Insert Query in Sql Data Source using Oracle Database, with
the parameters, and its connected with DetailView Control.
When I try to Insert through DetailView Control, Illegal...
|
by: hotadvice |
last post by:
hi there
i think this is an off topic question
but i think u folks ,,,here know the best....
so ....
case 1)
|
by: Alexandre Brisebois |
last post by:
I have been trying to use Linq o SQL to query an XML data column I
currently have in my DB,
but it seems that Linq to SQL sees a typed xml column as an XElement,
I don't want to get the full...
|
by: NatRoger |
last post by:
Hi,
We are using DB2 V7 (MVS) in our shop, which dont have the luxury of
the 'WITH clause' - CTE support to accomplish recursive queries.
Here is my problem -
Table1
From-ID To-ID
A1 ...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |