Click to See Complete Forum and Search --> : How to pickup latest date from database


Squall Leonhart
11-21-2003, 12:46 PM
Hi, guys.

Do you know how to pick up latest date from database?
Please take a look at following code.


<HTML>
<HEAD>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<%
Dim adoCon
Dim rsRequest
Dim strSQL
Set adoCon = Server.CreateObject("ADODB.Connection")
Set rsRequest = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT date FROM tblRequest"
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("tech_re.mdb")
rsRequest.CursorType = 3
rsRequest.Open strSQL, adoCon
%>
<table width=100% topmargin=0>
<TR valign=top>
<TD colspan=2 align=center ><FONT FACE=Arial,Helvetica SIZE=2 color=blue><B>TOP 10 IT HOTLIST</b></font></td>
</tr>
<TR>
<TD colspan=2 align=center WIDTH=300><FONT FACE=Arial,Helvetica SIZE=-1 color=blue><i>Last modified:<%=rsRequest("date")%> </i></font></td>
</tr>
<tr>
<TD WIDTH="300" ALIGN=LEFT><FONT FACE=Arial,Helvetica SIZE=-1 color=red><B>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="ITHotlist.xls" target=new>All IT Projects...</a></B></FONT></TD>
</TR>
</table>
<%'Reset server objects
rsRequest.Close
Set rsRequest = Nothing
Set adoCon = Nothing
%>

</BODY>
</HTML>


It's not picking up newest time. It's only picking up first one.
So what can I do?:(

rdoekes
11-21-2003, 12:55 PM
modify your sql statement to

strSQL = "SELECT TOP 1 date FROM tblRequest ORDER BY date DESC"

The reason why you only see 1 date is 'cause you do not loop through your recordset, but only view the first record.
The sql statement descibed above will only select 1 record with one field.

hope this helps

Squall Leonhart
11-21-2003, 01:17 PM
Exactly what I wanted.
Thank you very much.:)