[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Retrieve last record in field SQL query Select statement

Posted on 2010-09-14
6
Medium Priority
?
862 Views
Last Modified: 2012-05-10
I’m trying to write a SELECT statement that brings back the last record of a field (“RECORD”).

Would it look like this?:

Recordset1.Source = “SELECT TOP 1 * FROM JAX ORDER BY RECORD DESC”

Any assistance is greatly appreciated.

Thank you.
0
Comment
Question by:arendt73
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 7

Assisted Solution

by:tlovie
tlovie earned 600 total points
ID: 33677450
yes
0
 
LVL 43

Accepted Solution

by:
pcelba earned 800 total points
ID: 33677584
This really depends on the order definition.

SELECT TOP 1 * FROM JAX ORDER BY RECORD DESC

retrieves the last record based on the values of RECORD column. Is it correct?

If you need the most recently entered value then you would need to order the query by som etimestamp.

If you need the value which is stored in the physically last DBF record then you should use RECNO() for ordering (this query will work just on DBF file not on SQL Server):

SELECT TOP 1 RECNO(), * FROM JAX ORDER BY 1 DESC

Also the Recordset has MoveLast method, so you could use it ...
0
 

Author Comment

by:arendt73
ID: 33682302
I get the following error when using: SELECT TOP 1 * FROM JAX ORDER BY RECORD DESC

Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

/statusreports/jax/results-test.asp, line 13

When I mean the last record, I mean the latest entry into the RECORD field.
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\inetpub\wwwroot\statusreports\db\status.mdb"

Recordset1.Source = "SELECT TOP 1 * FROM JAX ORDER BY RECORD DESC"

Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 600 total points
ID: 33682335
if you get that error, it means that RECORD is not a column in the table...
of course, you might try to do this, presuming that RECORD is a reserved keyword:

Recordset1.Source = "SELECT TOP 1 * FROM JAX ORDER BY [RECORD] DESC"

Open in new window

0
 
LVL 43

Expert Comment

by:pcelba
ID: 33682862
If you are entering growing value into the RECORD column then above query should return the latest value.

Access 2007 does not require RECORD to be enclosed in brackets, so what was the problem?
0
 

Author Comment

by:arendt73
ID: 33682890
I forgot to change the name of the field.  My apologizes.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question