Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Find records with date field before today

Reply
Thread Tools

Find records with date field before today

 
 
!TG
Guest
Posts: n/a
 
      07-26-2005
I have a table with a date field.
All I want to do it get all the records with a date before today.
I tried the following:
"SELECT * FROM StateLicenses Where (Exp < #07/26/2005#) Order By
BranchNo,Satellite;"
"SELECT * FROM StateLicenses Where (Exp < 07/26/2005) Order By
BranchNo,Satellite;"
"SELECT * FROM StateLicenses Where (Exp < " & Now() & ") Order By
BranchNo,Satellite;"
"SELECT * FROM StateLicenses Where (Exp < #" & Now() & "#) Order By
BranchNo,Satellite;"
"SELECT * FROM StateLicenses Where (Exp < " & FormatDateTime(Now(),2) &
") Order By BranchNo,Satellite;"
"SELECT * FROM StateLicenses Where (Exp < #" & FormatDateTime(Now(),2) &
"#) Order By BranchNo,Satellite;"

and get errors such as:
Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.


The expected numbe is sometimes 1 and sometimes 3.
Please tell me what I am doing wrong.
 
Reply With Quote
 
 
 
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-26-2005
sql = "SELECT * FROM StateLicences WHERE Exp < DATE()"

I assume Exp should have a better column name...



"!TG" <> wrote in message
news:%...
>I have a table with a date field.
> All I want to do it get all the records with a date before today.
> I tried the following:
> "SELECT * FROM StateLicenses Where (Exp < #07/26/2005#) Order By
> BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < 07/26/2005) Order By
> BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < " & Now() & ") Order By
> BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < #" & Now() & "#) Order By
> BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < " & FormatDateTime(Now(),2) & ")
> Order By BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < #" & FormatDateTime(Now(),2) &
> "#) Order By BranchNo,Satellite;"
>
> and get errors such as:
> Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
>
> [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
>
>
> The expected numbe is sometimes 1 and sometimes 3.
> Please tell me what I am doing wrong.



 
Reply With Quote
 
 
 
 
Curt_C [MVP]
Guest
Posts: n/a
 
      07-26-2005
!TG wrote:
> I have a table with a date field.
> All I want to do it get all the records with a date before today.
> I tried the following:
> "SELECT * FROM StateLicenses Where (Exp < #07/26/2005#) Order By
> BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < 07/26/2005) Order By
> BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < " & Now() & ") Order By
> BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < #" & Now() & "#) Order By
> BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < " & FormatDateTime(Now(),2) &
> ") Order By BranchNo,Satellite;"
> "SELECT * FROM StateLicenses Where (Exp < #" & FormatDateTime(Now(),2) &
> "#) Order By BranchNo,Satellite;"
>
> and get errors such as:
> Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
>
> [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
>
>
> The expected numbe is sometimes 1 and sometimes 3.
> Please tell me what I am doing wrong.



"SELECT * FROM StateLicenses Where (Exp < '" & Now() & "') Order By
BranchNo,Satellite;"

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
 
Reply With Quote
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-26-2005
> "SELECT * FROM StateLicenses Where (Exp < '" & Now() & "') Order By
> BranchNo,Satellite;"


Why do this outside of the database? Access knows what NOW() is. Plus, I
don't think single quote delimiters will work well, assuming Exp is a Date
column...


 
Reply With Quote
 
Curt_C [MVP]
Guest
Posts: n/a
 
      07-26-2005
Aaron Bertrand [SQL Server MVP] wrote:
>>"SELECT * FROM StateLicenses Where (Exp < '" & Now() & "') Order By
>>BranchNo,Satellite;"

>
>
> Why do this outside of the database? Access knows what NOW() is. Plus, I
> don't think single quote delimiters will work well, assuming Exp is a Date
> column...
>
>


Till you said it I didn't realize it was Access. The reason I was
pushing it this way is that the DB may be in a different timezone then
the client, thinking the client wanted their time....guess it depends
what was used for the time when it was entered... hopefully it was
standardized with server time as you indicated though.....

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
 
Reply With Quote
 
!TG
Guest
Posts: n/a
 
      07-26-2005
Thanks for the replies.
EXP is type Date/Time in access database.
I also specified a format of short date after the problems began in a
wild stab at the dark.

I tried the below as recommended by Aaron
PSQL = "SELECT * FROM "
ThisTBL = PSQL & "StateLicenses Where (Exp < Date()) Order By
BranchNo,Satellite;"
PRS.Open ThisTBL, PDB
And got:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 2.

I tried the below as recommended by Curt_C
PSQL = "SELECT * FROM "
ThisTBL = PSQL & "StateLicenses Where (Exp < " & Now() & ")
Order By BranchNo,Satellite;"
PRS.Open ThisTBL, PDB
And got:
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
operator) in query expression '(Exp < 7/26/2005 2:48:25 PM)'.

Since that error was different I thought I might be on the right track
so I surrounded Now() with single quotes and pound signs, both of which
generated:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 2.

I tried the below as recommended by Aaron
PSQL = "SELECT * FROM "
ThisTBL = PSQL & "StateLicenses Where (Exp < Now()) Order By
BranchNo,Satellite;"
PRS.Open ThisTBL, PDB
And got:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 2.


I thought this query would be so simple and all the recommendations I
found on the internet were the same as yours...
I do appreciate the input, anything else?
Questions for me regarding my programming?
 
Reply With Quote
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-26-2005
Is Exp a reserved word? Try the very first query but surround Exp with
[Exp]

Also try

set PRS = PDB.Execute(ThisTBL)

I also suggest using more standard names, they cause far less confusion.
Typically connection objects are named conn and recordset objects are named
rs or objRS. Just makes the code easier for others to follow...

A


"!TG" <> wrote in message
news:ul$...
> Thanks for the replies.
> EXP is type Date/Time in access database.
> I also specified a format of short date after the problems began in a wild
> stab at the dark.
>
> I tried the below as recommended by Aaron
> PSQL = "SELECT * FROM "
> ThisTBL = PSQL & "StateLicenses Where (Exp < Date()) Order By
> BranchNo,Satellite;"
> PRS.Open ThisTBL, PDB
> And got:
> [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
> Expected 2.
>
> I tried the below as recommended by Curt_C
> PSQL = "SELECT * FROM "
> ThisTBL = PSQL & "StateLicenses Where (Exp < " & Now() & ")
> Order By BranchNo,Satellite;"
> PRS.Open ThisTBL, PDB
> And got:
> [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
> operator) in query expression '(Exp < 7/26/2005 2:48:25 PM)'.
>
> Since that error was different I thought I might be on the right track so
> I surrounded Now() with single quotes and pound signs, both of which
> generated:
> [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
> Expected 2.
>
> I tried the below as recommended by Aaron
> PSQL = "SELECT * FROM "
> ThisTBL = PSQL & "StateLicenses Where (Exp < Now()) Order By
> BranchNo,Satellite;"
> PRS.Open ThisTBL, PDB
> And got:
> [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
> Expected 2.
>
>
> I thought this query would be so simple and all the recommendations I
> found on the internet were the same as yours...
> I do appreciate the input, anything else?
> Questions for me regarding my programming?



 
Reply With Quote
 
!TG
Guest
Posts: n/a
 
      07-26-2005
Aaron Bertrand [SQL Server MVP] wrote:
> sql = "SELECT * FROM StateLicences WHERE Exp < DATE()"
>
> I assume Exp should have a better column name...
>
>
>
> "!TG" <> wrote in message
> news:%...
>
>>I have a table with a date field.
>>All I want to do it get all the records with a date before today.
>>I tried the following:
>>"SELECT * FROM StateLicenses Where (Exp < #07/26/2005#) Order By
>>BranchNo,Satellite;"
>>"SELECT * FROM StateLicenses Where (Exp < 07/26/2005) Order By
>>BranchNo,Satellite;"
>>"SELECT * FROM StateLicenses Where (Exp < " & Now() & ") Order By
>>BranchNo,Satellite;"
>>"SELECT * FROM StateLicenses Where (Exp < #" & Now() & "#) Order By
>>BranchNo,Satellite;"
>>"SELECT * FROM StateLicenses Where (Exp < " & FormatDateTime(Now(),2) & ")
>>Order By BranchNo,Satellite;"
>>"SELECT * FROM StateLicenses Where (Exp < #" & FormatDateTime(Now(),2) &
>>"#) Order By BranchNo,Satellite;"
>>
>>and get errors such as:
>>Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
>>
>>[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
>>
>>
>>The expected numbe is sometimes 1 and sometimes 3.
>>Please tell me what I am doing wrong.

>
>
>

Returned
[Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 2.
 
Reply With Quote
 
!TG
Guest
Posts: n/a
 
      07-26-2005
Curt_C [MVP] wrote:
> !TG wrote:
>
>> I have a table with a date field.
>> All I want to do it get all the records with a date before today.
>> I tried the following:
>> "SELECT * FROM StateLicenses Where (Exp < #07/26/2005#) Order By
>> BranchNo,Satellite;"
>> "SELECT * FROM StateLicenses Where (Exp < 07/26/2005) Order By
>> BranchNo,Satellite;"
>> "SELECT * FROM StateLicenses Where (Exp < " & Now() & ") Order By
>> BranchNo,Satellite;"
>> "SELECT * FROM StateLicenses Where (Exp < #" & Now() & "#) Order By
>> BranchNo,Satellite;"
>> "SELECT * FROM StateLicenses Where (Exp < " & FormatDateTime(Now(),2)
>> & ") Order By BranchNo,Satellite;"
>> "SELECT * FROM StateLicenses Where (Exp < #" & FormatDateTime(Now(),2)
>> & "#) Order By BranchNo,Satellite;"
>>
>> and get errors such as:
>> Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
>>
>> [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
>>
>>
>> The expected numbe is sometimes 1 and sometimes 3.
>> Please tell me what I am doing wrong.

>
>
>
> "SELECT * FROM StateLicenses Where (Exp < '" & Now() & "') Order By
> BranchNo,Satellite;"
>

That gave me
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
operator) in query expression '(Exp < 7/26/2005 2:48:25 PM)'.

Since that error was different I thought I might be on the right track
so I surrounded Now() with single quotes and pound signs, both of which
generated:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 2.
 
Reply With Quote
 
!TG
Guest
Posts: n/a
 
      07-26-2005
Aaron Bertrand [SQL Server MVP] wrote:
>>"SELECT * FROM StateLicenses Where (Exp < '" & Now() & "') Order By
>>BranchNo,Satellite;"

>
>
> Why do this outside of the database? Access knows what NOW() is. Plus, I
> don't think single quote delimiters will work well, assuming Exp is a Date
> column...
>
>

That gave me:
[Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 2.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Notice the date today? What happened 40 years ago today? richard Computer Support 10 07-29-2009 08:20 PM
ASP Date: get records with date = today (SQL Server) Vinnie Davidson ASP General 6 08-15-2005 07:28 PM
Calendar Date-Picker can't find date field (X,Y) randomblink@yahoo.com Javascript 0 01-03-2005 05:59 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57