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.
13,320 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,869 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,260 questions
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,597 questions
{count} votes

Accepted answer
  1. EchoLiu-MSFT 14,581 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 43,161 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 106.5K Reputation points


    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