Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How to get the last record .. Stored Procedure?

How to get the last record .. Stored Procedure?

Scheduled Pinned Locked Moved Database
questiondatabasesql-serversysadmintutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kindman_nb
    wrote on last edited by
    #1

    Hay .. in SQL server 2005 I can make any select statement , but how can I get the last record : like that id invNo 1 a1 2 a2 3 a3 @newinv nvarchar(10) output AS SET NOCOUNT ON begin SELECT * FROM table ORDER BY invNo end I want to get the field invNo of the last record then by substring function i can add One .. I hope my question is clear . thanks

    jooooo

    B R 2 Replies Last reply
    0
    • K kindman_nb

      Hay .. in SQL server 2005 I can make any select statement , but how can I get the last record : like that id invNo 1 a1 2 a2 3 a3 @newinv nvarchar(10) output AS SET NOCOUNT ON begin SELECT * FROM table ORDER BY invNo end I want to get the field invNo of the last record then by substring function i can add One .. I hope my question is clear . thanks

      jooooo

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      select top 1 invNo from table order by id desc


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

      R 1 Reply Last reply
      0
      • K kindman_nb

        Hay .. in SQL server 2005 I can make any select statement , but how can I get the last record : like that id invNo 1 a1 2 a2 3 a3 @newinv nvarchar(10) output AS SET NOCOUNT ON begin SELECT * FROM table ORDER BY invNo end I want to get the field invNo of the last record then by substring function i can add One .. I hope my question is clear . thanks

        jooooo

        R Offline
        R Offline
        Rob Graham
        wrote on last edited by
        #3

        "select top 1 InvNo from table order by id DESC" -- ASSUMES ID IS AN IDENTIY FIELD, OPR AT LEAST THAT THE LAST RECORD HAS THE HIGHEST id

        R 1 Reply Last reply
        0
        • B Blue_Boy

          select top 1 invNo from table order by id desc


          I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

          R Offline
          R Offline
          Rob Graham
          wrote on last edited by
          #4

          Great minds think alike...:-\

          1 Reply Last reply
          0
          • R Rob Graham

            "select top 1 InvNo from table order by id DESC" -- ASSUMES ID IS AN IDENTIY FIELD, OPR AT LEAST THAT THE LAST RECORD HAS THE HIGHEST id

            R Offline
            R Offline
            r_mohd
            wrote on last edited by
            #5

            try this: Select Max(idno) for last record and Min(idno).

            rmshah Developer

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups