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. Only get top X rows of a stored procedure's results set

Only get top X rows of a stored procedure's results set

Scheduled Pinned Locked Moved Database
databasesysadmintestingbeta-testinghelp
6 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.
  • Brian C HartB Offline
    Brian C HartB Offline
    Brian C Hart
    wrote on last edited by
    #1

    I have a question, I hope this has not been asked before But I have a stored procedure which I have to EXEC in order to get a results set, and then pop the results set into an Excel report. Problem is, the results set is known to have 100,000's of rows. Now, I've read on Google about SET ROWCOUNT and I did the following as a test...

    SET ROWCOUNT 5

    EXEC ....

    However, doing that gives me nothing back, not the top 5 rows of the results set like I expect. I don't want to put a TOP 5 (or TOP X you get the idea) in my SELECT inside the stored procedure because doing that will break functionality elsewhere. I just want the top X rows right now just for testing purposes, and then when I am ready to deploy I plan to have it give me the full query (the query runs as a scripted console app on a remote server somewhere at regularly scheduled times). Thanks for any inputs!

    Sincerely Yours, Brian Hart

    Regards,

    Dr. Brian Hart
    drbrianhart343@gmail.com email
    LinkedIn: https://www.linkedin.com/in/dr-brian-hart-astrophysicist-veteran/

    L C 2 Replies Last reply
    0
    • Brian C HartB Brian C Hart

      I have a question, I hope this has not been asked before But I have a stored procedure which I have to EXEC in order to get a results set, and then pop the results set into an Excel report. Problem is, the results set is known to have 100,000's of rows. Now, I've read on Google about SET ROWCOUNT and I did the following as a test...

      SET ROWCOUNT 5

      EXEC ....

      However, doing that gives me nothing back, not the top 5 rows of the results set like I expect. I don't want to put a TOP 5 (or TOP X you get the idea) in my SELECT inside the stored procedure because doing that will break functionality elsewhere. I just want the top X rows right now just for testing purposes, and then when I am ready to deploy I plan to have it give me the full query (the query runs as a scripted console app on a remote server somewhere at regularly scheduled times). Thanks for any inputs!

      Sincerely Yours, Brian Hart

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

      Brian C. Hart, Ph.D. wrote:

      I don't want to put a TOP 5 (or TOP X you get the idea) in my SELECT inside the stored procedure because doing that will break functionality elsewhere.

      Make a second version with a different name?

      I are Troll :suss:

      Brian C HartB 1 Reply Last reply
      0
      • Brian C HartB Brian C Hart

        I have a question, I hope this has not been asked before But I have a stored procedure which I have to EXEC in order to get a results set, and then pop the results set into an Excel report. Problem is, the results set is known to have 100,000's of rows. Now, I've read on Google about SET ROWCOUNT and I did the following as a test...

        SET ROWCOUNT 5

        EXEC ....

        However, doing that gives me nothing back, not the top 5 rows of the results set like I expect. I don't want to put a TOP 5 (or TOP X you get the idea) in my SELECT inside the stored procedure because doing that will break functionality elsewhere. I just want the top X rows right now just for testing purposes, and then when I am ready to deploy I plan to have it give me the full query (the query runs as a scripted console app on a remote server somewhere at regularly scheduled times). Thanks for any inputs!

        Sincerely Yours, Brian Hart

        C Offline
        C Offline
        Chris Meech
        wrote on last edited by
        #3

        How about

        create or replace procedure SomeProcedure (
        input_select_count integer default null
        )
        as
        ...
        ...
        begin
        ...
        if ( input_select_count is NULL )
        ....
        else
        ....

        Even better to have the count applied to your SQL as a parameter so that your code can control the number of rows returned. :)

        Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

        Brian C HartB 1 Reply Last reply
        0
        • C Chris Meech

          How about

          create or replace procedure SomeProcedure (
          input_select_count integer default null
          )
          as
          ...
          ...
          begin
          ...
          if ( input_select_count is NULL )
          ....
          else
          ....

          Even better to have the count applied to your SQL as a parameter so that your code can control the number of rows returned. :)

          Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

          Brian C HartB Offline
          Brian C HartB Offline
          Brian C Hart
          wrote on last edited by
          #4

          Thanks for the tip! I'll keep that in mind

          Sincerely Yours, Brian Hart

          Regards,

          Dr. Brian Hart
          drbrianhart343@gmail.com email
          LinkedIn: https://www.linkedin.com/in/dr-brian-hart-astrophysicist-veteran/

          1 Reply Last reply
          0
          • L Lost User

            Brian C. Hart, Ph.D. wrote:

            I don't want to put a TOP 5 (or TOP X you get the idea) in my SELECT inside the stored procedure because doing that will break functionality elsewhere.

            Make a second version with a different name?

            I are Troll :suss:

            Brian C HartB Offline
            Brian C HartB Offline
            Brian C Hart
            wrote on last edited by
            #5

            I did that and it worked! Thanks [:)]

            Sincerely Yours, Brian Hart

            Regards,

            Dr. Brian Hart
            drbrianhart343@gmail.com email
            LinkedIn: https://www.linkedin.com/in/dr-brian-hart-astrophysicist-veteran/

            L 1 Reply Last reply
            0
            • Brian C HartB Brian C Hart

              I did that and it worked! Thanks [:)]

              Sincerely Yours, Brian Hart

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

              You're welcome :)

              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