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 Cursor's record count (Transact-SQL) ?

How to get Cursor's record count (Transact-SQL) ?

Scheduled Pinned Locked Moved Database
databasetutorialquestion
5 Posts 3 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.
  • N Offline
    N Offline
    Naunt
    wrote on last edited by
    #1

    Dear all, Please advise how to get the record count of Cursor ?

    DECLARE @vendor_cursor CURSOR FOR
    SELECT BusinessEntityID, Name
    FROM Purchasing.Vendor
    WHERE PreferredVendorStatus = 1
    ORDER BY BusinessEntityID;

    OPEN @vendor_cursor;

    FETCH NEXT FROM @vendor_cursor
    INTO @vendor_id, @vendor_name;

    Thanks and best regards

    M L 2 Replies Last reply
    0
    • N Naunt

      Dear all, Please advise how to get the record count of Cursor ?

      DECLARE @vendor_cursor CURSOR FOR
      SELECT BusinessEntityID, Name
      FROM Purchasing.Vendor
      WHERE PreferredVendorStatus = 1
      ORDER BY BusinessEntityID;

      OPEN @vendor_cursor;

      FETCH NEXT FROM @vendor_cursor
      INTO @vendor_id, @vendor_name;

      Thanks and best regards

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Do you need the count before, during or after the cursor has run. Before - use select count(*) with your cursor query During and After - set up a @Count variable and increment it within your cursor Set @Count = @Count + 1 This question shows a dramatic lack of thinking, the solution is so simple.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • N Naunt

        Dear all, Please advise how to get the record count of Cursor ?

        DECLARE @vendor_cursor CURSOR FOR
        SELECT BusinessEntityID, Name
        FROM Purchasing.Vendor
        WHERE PreferredVendorStatus = 1
        ORDER BY BusinessEntityID;

        OPEN @vendor_cursor;

        FETCH NEXT FROM @vendor_cursor
        INTO @vendor_id, @vendor_name;

        Thanks and best regards

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        @@CURSOR_ROWS[^]

        N M 2 Replies Last reply
        0
        • L Lost User

          @@CURSOR_ROWS[^]

          N Offline
          N Offline
          Naunt
          wrote on last edited by
          #4

          Thank you for the reply @@CURSOR_ROWS works for me.

          1 Reply Last reply
          0
          • L Lost User

            @@CURSOR_ROWS[^]

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Excellent, there is another potentially useful keyword I have never used (or knew about).

            Never underestimate the power of human stupidity RAH

            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