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. Call Sp inside a SP and count the number of rows returned by the SP

Call Sp inside a SP and count the number of rows returned by the SP

Scheduled Pinned Locked Moved Database
databasesharepointhelp
3 Posts 2 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
    Kit Fisto
    wrote on last edited by
    #1

    Hi guys. I have a problem. I need to call a Stored Procedure inside a Stored Procedure and count the number of rows returned by the second SP. Something like this: COUNT(EXEC My_SP 1,1,1,1). That second SP returns a query with a x number or rows. Thanks in advance guys.

    G 1 Reply Last reply
    0
    • K Kit Fisto

      Hi guys. I have a problem. I need to call a Stored Procedure inside a Stored Procedure and count the number of rows returned by the second SP. Something like this: COUNT(EXEC My_SP 1,1,1,1). That second SP returns a query with a x number or rows. Thanks in advance guys.

      G Offline
      G Offline
      Goutam Patra
      wrote on last edited by
      #2

      Declare your second SP like

      CREATE PROCEDURE My_SP
      @Para1 AS INTEGER,
      @Para2 AS INTEGER,
      @Para3 AS INTEGER,
      @RecordCount AS INTEGER OUTPUT
      AS
      SET @RecordCount = (SELECT COUNT(*) FROM MYTABLE)
      GO

      In your first SP Call this like

      DECLARE @RecordCount AS INTEGER
      EXEC My_SP 1, 1, 1, RecordCount OUTPUT

      Thats it

      K 1 Reply Last reply
      0
      • G Goutam Patra

        Declare your second SP like

        CREATE PROCEDURE My_SP
        @Para1 AS INTEGER,
        @Para2 AS INTEGER,
        @Para3 AS INTEGER,
        @RecordCount AS INTEGER OUTPUT
        AS
        SET @RecordCount = (SELECT COUNT(*) FROM MYTABLE)
        GO

        In your first SP Call this like

        DECLARE @RecordCount AS INTEGER
        EXEC My_SP 1, 1, 1, RecordCount OUTPUT

        Thats it

        K Offline
        K Offline
        Kit Fisto
        wrote on last edited by
        #3

        Thanks man. Thats exactly what i was looking for.

        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