Problems with Date Query

Results 1 to 2 of 2

Thread: Problems with Date Query

  1. #1
    Join Date
    Dec 1969

    Default Problems with Date Query

    I&#039;m having problems with querying a Access DB looking for a record with a specific date. I think my query is written incorrectly, but I have never queried a date so I&#039;m not sure.<BR><BR>getVehicleSQL = "SELECT * FROM " & table & " WHERE (client_id="& clid &" AND First_name=&#039;" & vfnm & "&#039; AND Date=#" & vdat & "#);"<BR><BR>Response.Write getVehicleSQL<BR>set getVehicleID = Server.CreateObject("ADODB.Recordset")<BR>getVehic leID.Open getVehicleSQL, objConn, adOpenStatic, adLockReadOnly, adCmdText<BR><BR>Vehicle_id = getVehicleID("Vehicle_id")<BR><BR>getVehicleID.Clo se<BR>set getVehicleID = Nothing<BR><BR>On my Response.Write I get SELECT * FROM Car WHERE (client_id=27 AND First_name=&#039;Jeff&#039;s Auto&#039; AND Date=#5/27/2001 1:02:10 AM#); Then the page bombs, but I&#039;m not sure why. There is a record that fits these parameters.<BR>

  2. #2
    Join Date
    Dec 1969

    Default You should give error message...

    ...when you just say "I&#039;m having problems..." and "..the page bombs..." it doesn&#039;t really tell us much, does it???<BR><BR>In this case I&#039;m 90% sure I know what the problem is, but next time: Full code *AND* full text of error message, okay?<BR><BR>PROBLEM: The word "Date" is a keyword in Access SQL, so using it as a field name gives you a SQL syntax error.<BR><BR>SOLUTION: Either change the field name (recommended for future usage, at least) or enclose the name in [...] so SQL sees the you *do* mean to use it as a field name.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts