Forums

ASP

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>
&lt;%
Dim Recordset1__MMColParam
Recordset1__MMColParam = "1"
If (Request.QueryString("RCV_DOMSTA" &lt;&gt; "" Then
Recordset1__MMColParam = Request.QueryString("RCV_DOMSTA"
End If
%&gt;
&lt;%
Dim Recordset1__MMColParam2
Recordset1__MMColParam2 = "1"
If (Request.QueryString("rcv_stat" &lt;&gt; "" Then
Recordset1__MMColParam2 = Request.QueryString("rcv_stat"
End If
%&gt;
&lt;%
Dim Recordset1__MMColParam1
Recordset1__MMColParam1 = "1"
If (Request.QueryString("rcv_liq" &lt;&gt; "" Then
Recordset1__MMColParam1 = Request.QueryString("rcv_liq"
End If
%&gt;
&lt;%
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&gt;=" + Replace(Recordset1__MMColParam1, "'", "''" + ""
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%&gt;
&lt;%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%&gt;
&lt;form method="get" action="&lt;%=request.servervariables("path_info"%&gt;" &gt; &lt;p&gt;
State&lt;input name="rcv_domsta" type="text" size="15" /&gt;&lt;br /&gt;
Status&lt;input name="rcv_stat" type="text" size="15" /&gt;
&lt;br /&gt;
Date
&lt;input name="rcv_liq" type="text" id="rcv_liq" /&gt;
&lt;br /&gt;
&lt;input type="submit" /&gt;
&lt;/p&gt;
&lt;/form&gt;


&lt;% While ((Repeat1__numRows &lt;&gt; 0) AND (NOT Recordset1.EOF)) %&gt;
&lt;tr&gt;
&lt;td&gt;&lt;%=(Recordset1.Fields.Item("RCV_CMPNAM".Value)%&gt;&lt;/td&gt;
&lt;td&gt;&lt;%=(Recordset1.Fields.Item("RCV_TYPE".Value)%&gt;&lt;/td&gt;
&lt;td&gt;&lt;%=(Recordset1.Fields.Item("RCV_STAT".Value)%&gt;&lt;/td&gt;
&lt;td&gt;&lt;%=(Recordset1.Fields.Item("RCV_DOMSTA".Value)%&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%&gt;

&lt;%
Recordset1.Close()
Set Recordset1 = Nothing
%&gt;
</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
&lt;%
Dim rsOccupiedSlots__MMColParam
rsOccupiedSlots__MMColParam = "xyz"
If (Request.QueryString("SDate" &lt;&gt; "" Then
rsOccupiedSlots__MMColParam = Cstr(Request.QueryString("SDate")
End If
%&gt;

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.

Reply to this topic