473,811 Members | 3,220 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1711
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.calld ate) Between [enter start date]-2 And
[enter start date]));

Q
"Nick 'The database Guy'" <ni***********@ eads.comwrote in
news:11******** **************@ h48g2000cwc.goo glegroups.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.calld ate) Between [enter start date]-2 And
[enter start date]));

Q
"Nick 'The database Guy'" <ni***********@ eads.comwrote in
news:11******** **************@ h48g2000cwc.goo glegroups.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
16949
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 create a parameter query in a stored procedure, but how do I use the result set of a parameter query in a select query (in the same or another sp)? In short, if a select query contains a result table that is generated as a parameter query, how do I...
2
3426
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 information: 1. # of each product sold in STORE for DATE, and for the 3 days prior to DATE 2. Sum # of each product sold in STORE for days 5-8 previous to DATE 3. Sum # of each product sold in STORE for days 9-12 previous to DATE 4. Sum # of each...
6
4486
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 have I been able to adapt other people's solutions/tips to fit what I need. If anyone could please help me with the following it would be really appreciated, thank you! I need to generate a Report (say: repCrossTab) that grabs it's data from the...
5
3537
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 to 1800 stores of a national home improvement chain store. Every week I electronicaly receive an excel spreadsheet "inventory report" with 19,800 rows or records, which I import into my tblSalesData table. The table now has 10 weeks of data or...
1
2755
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 criteria should look like doing a previous day query. The test query I have done using SQL analyzer is (select * from mvs_store_all_data_time_change where mvs_creation_date like '060801%'). This returns the previous days data, but is hard...
6
2737
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 this: ALTER proc getProductCommScale @product As varchar(30), @TISCommRate As Decimal(5,2) OUTPUT, @BrokerCommRate As Decimal(5,2) OUTPUT, @Fee As Decimal(5,2) OUTPUT As if RTRIM(@product)='Imed' Select @TISCommRate=TISComm,...
1
2625
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 >= current date. Otherwise, user have to waste time to page up the pages to find the current date 2. I got a script of simple calendar from the web that use mktime() to create links on the calendar Task I need to let user view data earlier than...
0
2537
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 parameter. whenever I execute my stored procedure,It'll extract the previous 4 days data. e.g,If I can run on 16-11-2007 , It should extract 15,14,13,12 data and main thing is here
9
1546
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 it to accept it? tia, function MakeXclHeader($result){ $fields = mysql_num_fields($result); for ($i = 0; $i < $fields; $i++){
0
9730
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10392
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.