Forums
This topic is locked
Date in sql query
Posted 06 Dec 2005 20:53:43
1
has voted
06 Dec 2005 20:53:43 Richard Mariner posted:
I have the following code that works great til I add the date to it. In which case it ignores it and gives me the whole recordset instead of adding the date to the filter. Any ideas on a fix?Thanks!
Rich
<pre id=code><font face=courier size=2 id=code>
<%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.QueryString("RCV_DOMSTA" <> "" Then
Recordset1__MMColParam = Request.QueryString("RCV_DOMSTA"
End If
%>
<%
Dim Recordset1__MMColParam2
Recordset1__MMColParam2 = "1"
If (Request.QueryString("rcv_stat" <> "" Then
Recordset1__MMColParam2 = Request.QueryString("rcv_stat"
End If
%>
<%
Dim Recordset1__MMColParam1
Recordset1__MMColParam1 = "1"
If (Request.QueryString("rcv_liq" <> "" Then
Recordset1__MMColParam1 = Request.QueryString("rcv_liq"
End If
%>
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset"
Recordset1.ActiveConnection = MM_IntranetMM_STRING
Recordset1.Source = "SELECT * FROM rcvrdata WHERE RCV_DOMSTA = '" + Replace(Recordset1__MMColParam, "'", "''" + "' AND rcv_stat='" + Replace(Recordset1__MMColParam2, "'", "''" + "' and rcv_liq>=" + Replace(Recordset1__MMColParam1, "'", "''" + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<form method="get" action="<%=request.servervariables("path_info"%>" > <p>
State<input name="rcv_domsta" type="text" size="15" /><br />
Status<input name="rcv_stat" type="text" size="15" />
<br />
Date
<input name="rcv_liq" type="text" id="rcv_liq" />
<br />
<input type="submit" />
</p>
</form>
<% While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) %>
<tr>
<td><%=(Recordset1.Fields.Item("RCV_CMPNAM".Value)%></td>
<td><%=(Recordset1.Fields.Item("RCV_TYPE".Value)%></td>
<td><%=(Recordset1.Fields.Item("RCV_STAT".Value)%></td>
<td><%=(Recordset1.Fields.Item("RCV_DOMSTA".Value)%></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
</font id=code></pre id=code>
Replies
Replied 13 Dec 2005 02:20:37
13 Dec 2005 02:20:37 mark lawson replied:
Yeah this was a royal PITA for me until I realised that Access stores
dates in the US format internally, even when changing the LCID it
made nada difference.
Try this in your code:
When adding a date parameter use the code such as indicated below:
SELECT * FROM tblSchedule WHERE
AppDate = #" +Replace(rsOccupiedSlots__MMColParam, "'", "''" +"#
and above that Convert the date to a string first ie
<%
Dim rsOccupiedSlots__MMColParam
rsOccupiedSlots__MMColParam = "xyz"
If (Request.QueryString("SDate" <> "" Then
rsOccupiedSlots__MMColParam = Cstr(Request.QueryString("SDate")
End If
%>
hth
dates in the US format internally, even when changing the LCID it
made nada difference.
Try this in your code:
When adding a date parameter use the code such as indicated below:
SELECT * FROM tblSchedule WHERE
AppDate = #" +Replace(rsOccupiedSlots__MMColParam, "'", "''" +"#
and above that Convert the date to a string first ie
<%
Dim rsOccupiedSlots__MMColParam
rsOccupiedSlots__MMColParam = "xyz"
If (Request.QueryString("SDate" <> "" Then
rsOccupiedSlots__MMColParam = Cstr(Request.QueryString("SDate")
End If
%>
hth
Replied 13 Dec 2005 21:21:10
13 Dec 2005 21:21:10 Richard Mariner replied:
Thanks for the reply. I did eventually come to the same conclusion.