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

Parameter Query - need previous 2 days worth of data

Hi -

I've been struggling to produce a working parameter query that will
allow the end user to type in any date (mm/dd/yy) and obtain the
records of the previous 2 days. In other words, if the user types in
08/07/06, the records of 08/05/06, 08/06/06 and 08/07/06 will all
appear in the qry.

I have the following code, which is real basic, but I am running into
"the expression is typed incorrectly or is too complex etc".

SELECT [111].Start_Date
FROM 111
WHERE ((([111].[Start_Date])<=[Enter Start Date]-2));

Any help would greatly be appreciated.
Thanx in advance,
vf

Aug 8 '06 #1
5 1690
Hi Vin,

You need to use the Dateadd statement in the WHERE clause of the SQL.

The syntax of which is Dateadd("d", -2, [Enter Start Date])

So the where clause will look like this WHERE Start_Date [Enter Start
Date] AND Start_Date < Dateadd("d", -2, [Enter Start Date])

Good Luck

Nick
vinfurnier wrote:
Hi -

I've been struggling to produce a working parameter query that will
allow the end user to type in any date (mm/dd/yy) and obtain the
records of the previous 2 days. In other words, if the user types in
08/07/06, the records of 08/05/06, 08/06/06 and 08/07/06 will all
appear in the qry.

I have the following code, which is real basic, but I am running into
"the expression is typed incorrectly or is too complex etc".

SELECT [111].Start_Date
FROM 111
WHERE ((([111].[Start_Date])<=[Enter Start Date]-2));

Any help would greatly be appreciated.
Thanx in advance,
vf
Aug 8 '06 #2
Hi Nick -
Thanx for the quick reply!!!

I tried this and, allthough I didn't get the "typed incorrectly" error
message, I didn't get any results. However, when I type "Between" in
for the criteria (between 08/05/06 and 08/07/06), I do obtain a number
of records. I really don't want to have the end users do this, (too
many keystokes = too many errors). But, it looks like the query that
you sent me should work.

Where this is a linked table from another db offsite (I have no control
to change any of the settings to it), could it be something in the
Date/time format? My Start_Date field is in Date/Time with no Time
associated with it, just Date.

Anymore thoughts?
Thanx again for your time,
Nick 'The database Guy' wrote:
Hi Vin,

You need to use the Dateadd statement in the WHERE clause of the SQL.

The syntax of which is Dateadd("d", -2, [Enter Start Date])

So the where clause will look like this WHERE Start_Date [Enter Start
Date] AND Start_Date < Dateadd("d", -2, [Enter Start Date])

Good Luck

Nick
vinfurnier wrote:
Hi -

I've been struggling to produce a working parameter query that will
allow the end user to type in any date (mm/dd/yy) and obtain the
records of the previous 2 days. In other words, if the user types in
08/07/06, the records of 08/05/06, 08/06/06 and 08/07/06 will all
appear in the qry.

I have the following code, which is real basic, but I am running into
"the expression is typed incorrectly or is too complex etc".

SELECT [111].Start_Date
FROM 111
WHERE ((([111].[Start_Date])<=[Enter Start Date]-2));

Any help would greatly be appreciated.
Thanx in advance,
vf
Aug 8 '06 #3
Hello again Vin,

Maybe you should try with other values for instance, Dateadd("h", -48,
[Enter date])

It should work.

Good luck

Nick

vinfurnier wrote:
Hi Nick -
Thanx for the quick reply!!!

I tried this and, allthough I didn't get the "typed incorrectly" error
message, I didn't get any results. However, when I type "Between" in
for the criteria (between 08/05/06 and 08/07/06), I do obtain a number
of records. I really don't want to have the end users do this, (too
many keystokes = too many errors). But, it looks like the query that
you sent me should work.

Where this is a linked table from another db offsite (I have no control
to change any of the settings to it), could it be something in the
Date/time format? My Start_Date field is in Date/Time with no Time
associated with it, just Date.

Anymore thoughts?
Thanx again for your time,
Nick 'The database Guy' wrote:
Hi Vin,

You need to use the Dateadd statement in the WHERE clause of the SQL.

The syntax of which is Dateadd("d", -2, [Enter Start Date])

So the where clause will look like this WHERE Start_Date [Enter Start
Date] AND Start_Date < Dateadd("d", -2, [Enter Start Date])

Good Luck

Nick
vinfurnier wrote:
Hi -
>
I've been struggling to produce a working parameter query that will
allow the end user to type in any date (mm/dd/yy) and obtain the
records of the previous 2 days. In other words, if the user types in
08/07/06, the records of 08/05/06, 08/06/06 and 08/07/06 will all
appear in the qry.
>
I have the following code, which is real basic, but I am running into
"the expression is typed incorrectly or is too complex etc".
>
SELECT [111].Start_Date
FROM 111
WHERE ((([111].[Start_Date])<=[Enter Start Date]-2));
>
Any help would greatly be appreciated.
Thanx in advance,
vf
Aug 8 '06 #4
When using parameters, if you declare the parameter and its
type, you can use it in multiple places, but it will ask for
input only one time.

Even if you intend to use a parameter only once in the query,
it's a good idea to declare it, ESPECIALLY with dates.

This works:
PARAMETERS [Enter Start Date] DateTime;
SELECT Table2.calldate
FROM Table2
WHERE (((Table2.calldate) Between [enter start date]-2 And
[enter start date]));

Q
"Nick 'The database Guy'" <ni***********@eads.comwrote in
news:11**********************@h48g2000cwc.googlegr oups.com:
Hello again Vin,

Maybe you should try with other values for instance,
Dateadd("h", -48, [Enter date])

It should work.

Good luck

Nick

vinfurnier wrote:
>Hi Nick -
Thanx for the quick reply!!!

I tried this and, allthough I didn't get the "typed
incorrectly" error message, I didn't get any results.
However, when I type "Between" in for the criteria (between
08/05/06 and 08/07/06), I do obtain a number of records. I
really don't want to have the end users do this, (too many
keystokes = too many errors). But, it looks like the query
that you sent me should work.

Where this is a linked table from another db offsite (I have
no control to change any of the settings to it), could it be
something in the Date/time format? My Start_Date field is in
Date/Time with no Time associated with it, just Date.

Anymore thoughts?
Thanx again for your time,
Nick 'The database Guy' wrote:
Hi Vin,

You need to use the Dateadd statement in the WHERE clause
of the SQL.

The syntax of which is Dateadd("d", -2, [Enter Start Date])

So the where clause will look like this WHERE Start_Date >
[Enter Start Date] AND Start_Date < Dateadd("d", -2, [Enter
Start Date])

Good Luck

Nick
vinfurnier wrote:
Hi -

I've been struggling to produce a working parameter query
that will allow the end user to type in any date
(mm/dd/yy) and obtain the records of the previous 2 days.
In other words, if the user types in 08/07/06, the
records of 08/05/06, 08/06/06 and 08/07/06 will all
appear in the qry.

I have the following code, which is real basic, but I am
running into "the expression is typed incorrectly or is
too complex etc".

SELECT [111].Start_Date
FROM 111
WHERE ((([111].[Start_Date])<=[Enter Start Date]-2));

Any help would greatly be appreciated.
Thanx in advance,
vf



--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 8 '06 #5
Hi Bob -

Perfect!!!!
Just what I was looking for.
Thanx again,
vf
Bob Quintal wrote:
When using parameters, if you declare the parameter and its
type, you can use it in multiple places, but it will ask for
input only one time.

Even if you intend to use a parameter only once in the query,
it's a good idea to declare it, ESPECIALLY with dates.

This works:
PARAMETERS [Enter Start Date] DateTime;
SELECT Table2.calldate
FROM Table2
WHERE (((Table2.calldate) Between [enter start date]-2 And
[enter start date]));

Q
"Nick 'The database Guy'" <ni***********@eads.comwrote in
news:11**********************@h48g2000cwc.googlegr oups.com:
Hello again Vin,

Maybe you should try with other values for instance,
Dateadd("h", -48, [Enter date])

It should work.

Good luck

Nick

vinfurnier wrote:
Hi Nick -
Thanx for the quick reply!!!

I tried this and, allthough I didn't get the "typed
incorrectly" error message, I didn't get any results.
However, when I type "Between" in for the criteria (between
08/05/06 and 08/07/06), I do obtain a number of records. I
really don't want to have the end users do this, (too many
keystokes = too many errors). But, it looks like the query
that you sent me should work.

Where this is a linked table from another db offsite (I have
no control to change any of the settings to it), could it be
something in the Date/time format? My Start_Date field is in
Date/Time with no Time associated with it, just Date.

Anymore thoughts?
Thanx again for your time,
Nick 'The database Guy' wrote:
Hi Vin,

You need to use the Dateadd statement in the WHERE clause
of the SQL.

The syntax of which is Dateadd("d", -2, [Enter Start Date])

So the where clause will look like this WHERE Start_Date >
[Enter Start Date] AND Start_Date < Dateadd("d", -2, [Enter
Start Date])

Good Luck

Nick
vinfurnier wrote:
Hi -
>
I've been struggling to produce a working parameter query
that will allow the end user to type in any date
(mm/dd/yy) and obtain the records of the previous 2 days.
In other words, if the user types in 08/07/06, the
records of 08/05/06, 08/06/06 and 08/07/06 will all
appear in the qry.
>
I have the following code, which is real basic, but I am
running into "the expression is typed incorrectly or is
too complex etc".
>
SELECT [111].Start_Date
FROM 111
WHERE ((([111].[Start_Date])<=[Enter Start Date]-2));
>
Any help would greatly be appreciated.
Thanx in advance,
vf

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com
Aug 9 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
2
by: tedhekman | last post by:
Hi there! I am pretty new to Access, have been loving learning it! I have a problem here I can't even begin to figure out. Here is what I need: Given 1 Date and 1 Store, retrieve the following...
6
by: tizmagik | last post by:
I am having a lot of difficulty generating a CrossTab Query based report. I have looked online for several tutorials and whatnot but I have not been able to really find what I'm looking for, nor...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
1
by: Riaan | last post by:
Hi There, I am a newby with SQL and I am trying to run a query on a date/time field. The query is for the previous date. I would like to create this as a criteria in a view, but not sure what the...
6
by: c676228 | last post by:
Hi everyone, I wrote a store procedure that fetch one row data in the database based on the parameter value I entered. After I created the store procedure, the store procedure code looks like...
1
osward
by: osward | last post by:
Hi everyone, Background 1. I have a table that consits 400+ rows of data and is growing by day. The table already has paging links at the bottom but I restricted to display rows of data only >=...
0
by: Satishkeshetty | last post by:
Hi Experts, Could you please help me in the below query? Please help in the below situation, how can create the stored Procedure. I need to create a stored procedure and need to pass date...
9
by: JRough | last post by:
I'm getting the error message that the parameter passed to the function is not a valid resource. The parameter is $result and it is from a query in a switch statement. What do I have to do to get...
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
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: 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:
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
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.