last function in sql server

gholamreza rezaie 61 Reputation points

hello my friends .
i need last fee of our buying.
like this image i write script but my result is
last' is not a recognized built-in function name .

two table that you see in image is my tables that i use them for my main script.

thanks alot for your guiding131606-question-about-last-function.jpg

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
9,882 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,372 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,109 questions
{count} votes

Accepted answer
  1. EchoLiu-MSFT 14,516 Reputation points

    Hi @gholamreza rezaie

    As Olaf said, the LAST function is not a built-in function of SQL Server,it is only supported in MS Access.In SQL Server, the LAST function can be replaced by the method mentioned by Erland.

    Applied to your code should look like this:

    SELECT TOP 1 Fee FROM i  
    LEFT JOIN r  
    ON r.condition=i.condition  

    If you have any question, please feel free to let me know.


    If the answer is helpful, please click "Accept Answer" and upvote it.

2 additional answers

Sort by: Most helpful
  1. Olaf Helper 29,276 Reputation points

    LAST is not a valid Transact SQL command.

    Please post table design as DDL, some sample data as DML statement and the expected result.

    0 comments No comments

  2. Erland Sommarskog 78,826 Reputation points MVP


    SELECT TOP 1 Fee
    FROM ...

    But this is quite much a guess on my part of what you are looking for.

    0 comments No comments