last function in sql server

gholamreza rezaie 61 Reputation points
2021-09-13T12:23:16.417+00:00

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 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.
3,066 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,344 questions
Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

Accepted answer
  1. EchoLiu-MSFT 14,621 Reputation points
    2021-09-14T01:48:30.89+00:00

    Hi @gholamreza rezaie
    131781-image.png

    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  
    ORDER BY [DATE] DESC;  
    

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

    Regards
    Echo


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


2 additional answers

Sort by: Most helpful
  1. Olaf Helper 47,516 Reputation points
    2021-09-13T12:51:47.127+00:00

    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 121.9K Reputation points MVP Volunteer Moderator
    2021-09-13T21:39:53.493+00:00

    Maybe:

    SELECT TOP 1 Fee
    FROM ...
    ORDER BY Date DESC
    

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.