I am developing a database in an access project (.adp) and I need to use the (Last) function. What is the equivalent that will work with SQL Server??????????
There is no equivalent for LAST in SQL Server. Table order implied by LAST (and FIRST) is not a relational concept. SQL Server is more compliant to the relational model than Access in this regard.
If the table in question has an identity column, datetime column, or other incrementing column then the MAX function can be used in place of LAST. You can also use the TOP predicate to select the Last n (or First n) rows from a table.
Examples:
/* Find first value */
Select min(colA) From table
Select Top 1 colA From table order by colA
/* Find last value */
Select max(colA) From table
Select Top 1 colA From table order by colA desc Terry L. Broadbent
faq183-874 contains some tips and ideas for posting questions in these forums. Please review it and comment if you have time. NOTE: Reference to the FAQ is part of my signature and is not directed at any individual.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.