By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,659 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,659 IT Pros & Developers. It's quick & easy.

Date in Query

P: n/a
I have a Query that consist of a lot of different sales data, and one of the
colums are different date. The date goes from 1jan2003 til 31jan2003. in
this Query I only want the salesdata for 1jan2003. How do I remove the dates
, 2jan2003 til 31jan2003 without removing them from the table, from the
Query? (Because I want to use the data for 2jan2003 etc later in other
queries)

-kenneth
Nov 12 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Example:

Select * From tblMyTable Where DateField = #1/1/2003#

This will select all records from the table where the date field is 1 Jan
2003. The query wants the date formatted in US format. The # signs are date
delimiters so that Access knows that this is a date and not division. If you
are going to make multiple queries such as this one, you may want to look in
the help file for Parameter Queries. This will cause the query to prompt you
for the date when you run it.

--
Wayne Morgan
Microsoft Access MVP
"Kenneth" <sn*******@hotmail.com> wrote in message
news:c6**********@dolly.uninett.no...
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in
this Query I only want the salesdata for 1jan2003. How do I remove the dates , 2jan2003 til 31jan2003 without removing them from the table, from the
Query? (Because I want to use the data for 2jan2003 etc later in other
queries)

-kenneth

Nov 12 '05 #2

P: n/a
I have tried the formula:
Select * From tblMyTable Where DateField = #1/1/2003#

and changed MyTable to Date, which is the name of my column with date, but
it doesn't work.

Have I done anything wrong?

-kenneth

--
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:VJ**************@newssvr16.news.prodigy.com.. .
Example:

Select * From tblMyTable Where DateField = #1/1/2003#

This will select all records from the table where the date field is 1 Jan
2003. The query wants the date formatted in US format. The # signs are date delimiters so that Access knows that this is a date and not division. If you are going to make multiple queries such as this one, you may want to look in the help file for Parameter Queries. This will cause the query to prompt you for the date when you run it.

--
Wayne Morgan
Microsoft Access MVP
"Kenneth" <sn*******@hotmail.com> wrote in message
news:c6**********@dolly.uninett.no...
I have a Query that consist of a lot of different sales data, and one of

the
colums are different date. The date goes from 1jan2003 til 31jan2003. in
this Query I only want the salesdata for 1jan2003. How do I remove the

dates
, 2jan2003 til 31jan2003 without removing them from the table, from the
Query? (Because I want to use the data for 2jan2003 etc later in other
queries)

-kenneth


Nov 12 '05 #3

P: n/a
Kenneth wrote:
I have tried the formula:
Select * From tblMyTable Where DateField = #1/1/2003#

and changed MyTable to Date, which is the name of my column with date, but
it doesn't work.

Have I done anything wrong?
Yes. What is your table name? Go to the database window and select
Tables. Find out what the table name is your are designing your query
around. Tmen substitute tblMyTable to that name. Now open the table in
design mode. Determine the name of your date field to filter on. Close
the table. Substitute DateField with the name of the field.

Did you have a brain freeze :-)


-kenneth

--
"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:VJ**************@newssvr16.news.prodigy.com.. .
Example:

Select * From tblMyTable Where DateField = #1/1/2003#

This will select all records from the table where the date field is 1 Jan
2003. The query wants the date formatted in US format. The # signs are


date
delimiters so that Access knows that this is a date and not division. If


you
are going to make multiple queries such as this one, you may want to look


in
the help file for Parameter Queries. This will cause the query to prompt


you
for the date when you run it.


Nov 12 '05 #4

P: n/a
The name of my table is "deliveries", and my column inside that table is
named "date".
The formula now is then:
Expr1: (Select * From [levering] Where date = #1/1/2003#)
but this gives me an errormessage:
"You have written a subquery that can return more than one field without
using the EXISTS reserved word in the main query's FROM clause. Revise the
select statement of the subquery to request only one field."

How do I "Determine the name of your date field to filter on"?

-kenneth

....my brain needs a quick start up :)

--

"Salad" <oi*@vinegar.com> wrote in message
news:C6******************@newsread1.news.pas.earth link.net...
Kenneth wrote:
I have tried the formula:
Select * From tblMyTable Where DateField = #1/1/2003#

and changed MyTable to Date, which is the name of my column with date, but it doesn't work.

Have I done anything wrong?


Yes. What is your table name? Go to the database window and select
Tables. Find out what the table name is your are designing your query
around. Tmen substitute tblMyTable to that name. Now open the table in
design mode. Determine the name of your date field to filter on. Close
the table. Substitute DateField with the name of the field.

Did you have a brain freeze :-)


-kenneth

--
"Wayne Morgan" <co***************************@hotmail.com> wrote in message news:VJ**************@newssvr16.news.prodigy.com.. .
Example:

Select * From tblMyTable Where DateField = #1/1/2003#

This will select all records from the table where the date field is 1 Jan2003. The query wants the date formatted in US format. The # signs are


date
delimiters so that Access knows that this is a date and not division. If


you
are going to make multiple queries such as this one, you may want to
look
in
the help file for Parameter Queries. This will cause the query to prompt


you
for the date when you run it.

Nov 12 '05 #5

P: n/a
You are not using "deliveries" as the table. Also you have named a
column using an Access reserved word (date) - you are most likely
confusing Access. Rename the field to something else (not reserved,
that is). The SQL statement should be fine then.

Select * From deliveries Where Mydate = #1/1/2003#

- Jim

On Thu, 29 Apr 2004 23:59:21 +0200, "Kenneth" <sn*******@hotmail.com>
wrote:
The name of my table is "deliveries", and my column inside that table is
named "date".
The formula now is then:
Expr1: (Select * From [levering] Where date = #1/1/2003#)
but this gives me an errormessage:
"You have written a subquery that can return more than one field without
using the EXISTS reserved word in the main query's FROM clause. Revise the
select statement of the subquery to request only one field."

How do I "Determine the name of your date field to filter on"?

-kenneth

...my brain needs a quick start up :)

--

"Salad" <oi*@vinegar.com> wrote in message
news:C6******************@newsread1.news.pas.eart hlink.net...
Kenneth wrote:
> I have tried the formula:
> Select * From tblMyTable Where DateField = #1/1/2003#
>
> and changed MyTable to Date, which is the name of my column with date,but > it doesn't work.
>
> Have I done anything wrong?


Yes. What is your table name? Go to the database window and select
Tables. Find out what the table name is your are designing your query
around. Tmen substitute tblMyTable to that name. Now open the table in
design mode. Determine the name of your date field to filter on. Close
the table. Substitute DateField with the name of the field.

Did you have a brain freeze :-)

>
> -kenneth
>
> --
> "Wayne Morgan" <co***************************@hotmail.com> wrote inmessage > news:VJ**************@newssvr16.news.prodigy.com.. .
>
>>Example:
>>
>>Select * From tblMyTable Where DateField = #1/1/2003#
>>
>>This will select all records from the table where the date field is 1Jan >>2003. The query wants the date formatted in US format. The # signs are
>
> date
>
>>delimiters so that Access knows that this is a date and not division. If
>
> you
>
>>are going to make multiple queries such as this one, you may want tolook >
> in
>
>>the help file for Parameter Queries. This will cause the query to prompt
>
> you
>
>>for the date when you run it.
>>



Nov 12 '05 #6

P: n/a
My Tables is still named deliveries, but my date-column is named "MyDate"
now.
My formula is like this:
Expr1: [Select * From deliveries Where MyDate = #1/1/2003#]

but when I select the "query view" then I get this message:
"Enter Parameter Value. select * From deliveries Where MyDate = #1/1/2003#"

I still see all my rows (with date 1/1/2003, 2/1/2003 etc.) but the new
column consist of whatever I add in the "Enter Parameter Value"-field.

What is wrong this time, and what should I do?

-kenneth

--

"Jim Allensworth" <ji****@Notdatacentricsolutions.com> wrote in message
news:40****************@news.west.earthlink.net...
You are not using "deliveries" as the table. Also you have named a
column using an Access reserved word (date) - you are most likely
confusing Access. Rename the field to something else (not reserved,
that is). The SQL statement should be fine then.

Select * From deliveries Where Mydate = #1/1/2003#

- Jim

On Thu, 29 Apr 2004 23:59:21 +0200, "Kenneth" <sn*******@hotmail.com>
wrote:
The name of my table is "deliveries", and my column inside that table is
named "date".
The formula now is then:
Expr1: (Select * From [levering] Where date = #1/1/2003#)
but this gives me an errormessage:
"You have written a subquery that can return more than one field without
using the EXISTS reserved word in the main query's FROM clause. Revise theselect statement of the subquery to request only one field."

How do I "Determine the name of your date field to filter on"?

-kenneth

...my brain needs a quick start up :)

--

"Salad" <oi*@vinegar.com> wrote in message
news:C6******************@newsread1.news.pas.eart hlink.net...
Kenneth wrote:

> I have tried the formula:
> Select * From tblMyTable Where DateField = #1/1/2003#
>
> and changed MyTable to Date, which is the name of my column with date,
but
> it doesn't work.
>
> Have I done anything wrong?

Yes. What is your table name? Go to the database window and select
Tables. Find out what the table name is your are designing your query
around. Tmen substitute tblMyTable to that name. Now open the table

in design mode. Determine the name of your date field to filter on. Close the table. Substitute DateField with the name of the field.

Did you have a brain freeze :-)
>
> -kenneth
>
> --
> "Wayne Morgan" <co***************************@hotmail.com> wrote in

message
> news:VJ**************@newssvr16.news.prodigy.com.. .
>
>>Example:
>>
>>Select * From tblMyTable Where DateField = #1/1/2003#
>>
>>This will select all records from the table where the date field is 1

Jan
>>2003. The query wants the date formatted in US format. The # signs are >
> date
>
>>delimiters so that Access knows that this is a date and not division. If >
> you
>
>>are going to make multiple queries such as this one, you may want to

look
>
> in
>
>>the help file for Parameter Queries. This will cause the query to prompt >
> you
>
>>for the date when you run it.
>>



Nov 12 '05 #7

P: n/a
Kenneth wrote:
My Tables is still named deliveries, but my date-column is named "MyDate"
now.
My formula is like this:
Expr1: [Select * From deliveries Where MyDate = #1/1/2003#]

but when I select the "query view" then I get this message:
"Enter Parameter Value. select * From deliveries Where MyDate = #1/1/2003#"

I still see all my rows (with date 1/1/2003, 2/1/2003 etc.) but the new
column consist of whatever I add in the "Enter Parameter Value"-field.

What is wrong this time, and what should I do?

-kenneth


I don't think Access wants you to enter into one column your entire
select statement. BTW. the [] around your statement indicates to
Access that your select statement is a field. If in a criteria row, a
parameter.

The easiest way to get you back on track is to click on the query tab,
select New/Design. Select your Delivery table, click Close. Now drag
the * in the table delivery table to the field row. Drag the field
MyDate to the second row. Uncheck the SHOW checkbox. Enter #1/1/2003#
in the criteria row for MyDate.

Click View/Datasheet from the menu to check the results. Click View/SQL
to see the SQL Statement.

One other thing. You could copy the SQL statement in your expression,
and then click View/SQL and cut out whatever you currently have and
paste in the statement from your expression.

Definite brain freeze.

Nov 12 '05 #8

P: n/a
Hi-

I have a table with dates in it also. I usually use a parameter
expression in the criteria box for the field I want to use.

For example: I have a field named ContactDate. In "Design View" of my
query, I enter the following criteria for ContactDate:

Between [Enter Beginning Date] And [Enter Ending Date]

Then when I run the query, I can enter the beginning date and the
ending date.

The text between the braces, [], can be anything you want. I usually
say "Enter Beginning Date" and "Enter Ending Date" so that the user
knows what to enter. The text between the braces, [], are instructions
for what you want the user to enter. For example if you're searching
for a country, it would be: [Enter a Country]. The limiting is done by
the keywords, "Between" and "And."

However when I tried the criteria: [Enter a Date] for ContactDate, my
query only returned 1 record when I have 3. So, I'm not sure how well
it will work for a single date with multiple records.

Well I hope this gave you another idea even though I don't know how to
get a single date to return more than 1 record. I'm looking through
one of my books, Microsoft Access 2002 Inside Out. If I find an
answer, I'll post it!

Hope this gives you an idea,

Megan
Nov 12 '05 #9

P: n/a
Megan wrote:
Hi-

I have a table with dates in it also. I usually use a parameter
expression in the criteria box for the field I want to use.

For example: I have a field named ContactDate. In "Design View" of my
query, I enter the following criteria for ContactDate:

Between [Enter Beginning Date] And [Enter Ending Date]

Then when I run the query, I can enter the beginning date and the
ending date.

The text between the braces, [], can be anything you want. I usually
say "Enter Beginning Date" and "Enter Ending Date" so that the user
knows what to enter. The text between the braces, [], are instructions
for what you want the user to enter. For example if you're searching
for a country, it would be: [Enter a Country]. The limiting is done by
the keywords, "Between" and "And."

However when I tried the criteria: [Enter a Date] for ContactDate, my
query only returned 1 record when I have 3. So, I'm not sure how well
it will work for a single date with multiple records.
It should work like a champ.
Well I hope this gave you another idea even though I don't know how to
get a single date to return more than 1 record. I'm looking through
one of my books, Microsoft Access 2002 Inside Out. If I find an
answer, I'll post it!
I create a table called Table1. I added 3 date records. The first
record I stored Date(), the next 2 I stored Now(). I then ran a query
to select records for today. The query returned 1 record as expected.

Date stores the date and also the time of 00:00:00. So when the
criteria is Date and you have some now values ex: 4/30/2004 12:01:13
then that will never equal 4/30/2004 00:00:00.

If you have Now()'s then you need to check for equal Date and less than
Date+1.

I am curious. I have never used the [Enter Date] method in any of my
queries, forms, or reports. Do you use that method in an application or
do you use that because you mostly work with your data in the database
window? Or do you pass parameters to the query? I've seen it where the
developer had about 5 prompts in the query and each time the popup was
displayed to enter data I became more frustrated and wondered how many
more prompts I'd have to answer until I hit pay dirt.

Hope this gives you an idea,

Megan


Nov 12 '05 #10

P: n/a
Ken,

Access won't accept a subquery in an expession like this. If there is only
one record that will be returned by the expression, you can use DLookup
instead. What is/are the table(s) in the query in which you are trying to
add this expression?

--
Wayne Morgan
MS Access MVP
"Kenneth" <sn*******@hotmail.com> wrote in message
news:c6**********@dolly.uninett.no...
My Tables is still named deliveries, but my date-column is named "MyDate"
now.
My formula is like this:
Expr1: [Select * From deliveries Where MyDate = #1/1/2003#]

but when I select the "query view" then I get this message:
"Enter Parameter Value. select * From deliveries Where MyDate = #1/1/2003#"
I still see all my rows (with date 1/1/2003, 2/1/2003 etc.) but the new
column consist of whatever I add in the "Enter Parameter Value"-field.

What is wrong this time, and what should I do?

-kenneth

Nov 12 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.