access_asp thread: Lookup table using Dates
Message #1 by jmendez@k... on Thu, 6 Jun 2002 00:40:23
|
|
i'm trying to search a table using a date.
The results of my query shows all records that match the reqprty field and
disregards the date (entered_ts field).
Am I doing something wrong. Please help. Thank You.
Below is my code.
Set objCommand = Server.CreateObject("ADODB.Command")
strRecord5 = Request.Form("datefld")
strRecord = "REPAIR"
strRecord2 = "EMERGENCY"
strRecord3 = "TROUBLE"
strRecord4 = "TRBL-SHOOT"
' Connect to Database
objCommand.ActiveConnection = "MPET32"
' Create SQL Statement
objCommand.CommandText = "SELECT * FROM History " & _
"WHERE reqprty LIKE '%" & strRecord & "%'" & _
" OR reqprty LIKE '%" & strRecord2 & "%'" & _
" OR reqprty LIKE '%" & strRecord3 & "%'" & _
" OR reqprty LIKE '%" & strRecord4 & "%'" & _
" AND entered_ts LIKE '#" & strRecord5 & "#'" &_
" ORDER BY entered_ts"
objCommand.CommandType = adCmdText
Message #2 by "Ken Schaefer" <ken@a...> on Thu, 6 Jun 2002 12:39:29 +1000
|
|
Do not use LIKE when querying a date field.
You must use = or you can use BETWEEN (if you want to query for a date
range)
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <jmendez@k...>
Subject: [access_asp] Lookup table using Dates
: i'm trying to search a table using a date.
:
: The results of my query shows all records that match the reqprty field and
: disregards the date (entered_ts field).
:
: Am I doing something wrong. Please help. Thank You.
:
: Below is my code.
:
:
: Set objCommand = Server.CreateObject("ADODB.Command")
:
: strRecord5 = Request.Form("datefld")
: strRecord = "REPAIR"
: strRecord2 = "EMERGENCY"
: strRecord3 = "TROUBLE"
: strRecord4 = "TRBL-SHOOT"
:
: ' Connect to Database
: objCommand.ActiveConnection = "MPET32"
:
: ' Create SQL Statement
: objCommand.CommandText = "SELECT * FROM History " & _
: "WHERE reqprty LIKE '%" & strRecord & "%'" & _
: " OR reqprty LIKE '%" & strRecord2 & "%'" & _
: " OR reqprty LIKE '%" & strRecord3 & "%'" & _
: " OR reqprty LIKE '%" & strRecord4 & "%'" & _
: " AND entered_ts LIKE '#" & strRecord5 & "#'"
&_
: " ORDER BY entered_ts"
:
: objCommand.CommandType = adCmdText
|