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. Get row count and data set from sproc

Get row count and data set from sproc

Scheduled Pinned Locked Moved Database
question
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.
  • R Offline
    R Offline
    RCoate
    wrote on last edited by
    #1

    I am currently using a sproc like the one below to get both a dataset and a count of the rows returned. Is there a better way to do this?

    @Filter		int,
    @theRows	int output
    

    AS
    BEGIN
    SELECT
    Field1,
    Field2
    FROM
    MyTable
    WHERE
    FilterField=@Filter

    SET @theRows=(select count(\*) from MyTable WHERE FilterField=@Filter)
    

    END

    Thanks.

    A N 2 Replies Last reply
    0
    • R RCoate

      I am currently using a sproc like the one below to get both a dataset and a count of the rows returned. Is there a better way to do this?

      @Filter		int,
      @theRows	int output
      

      AS
      BEGIN
      SELECT
      Field1,
      Field2
      FROM
      MyTable
      WHERE
      FilterField=@Filter

      SET @theRows=(select count(\*) from MyTable WHERE FilterField=@Filter)
      

      END

      Thanks.

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Try this

      @Filter		int,	@theRows	int output
      

      AS
      BEGIN
      SELECT Field1, Field2
      FROM MyTable
      WHERE FilterField=@Filter

      SELECT @theRows = @@ROWCOUNT
      END

      Bob Ashfield Consultants Ltd

      R 1 Reply Last reply
      0
      • A Ashfield

        Try this

        @Filter		int,	@theRows	int output
        

        AS
        BEGIN
        SELECT Field1, Field2
        FROM MyTable
        WHERE FilterField=@Filter

        SELECT @theRows = @@ROWCOUNT
        END

        Bob Ashfield Consultants Ltd

        R Offline
        R Offline
        RCoate
        wrote on last edited by
        #3

        I knew there was a better way than doing another select/from Thanks Bob.

        A 1 Reply Last reply
        0
        • R RCoate

          I knew there was a better way than doing another select/from Thanks Bob.

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          No problem.

          Bob Ashfield Consultants Ltd

          1 Reply Last reply
          0
          • R RCoate

            I am currently using a sproc like the one below to get both a dataset and a count of the rows returned. Is there a better way to do this?

            @Filter		int,
            @theRows	int output
            

            AS
            BEGIN
            SELECT
            Field1,
            Field2
            FROM
            MyTable
            WHERE
            FilterField=@Filter

            SET @theRows=(select count(\*) from MyTable WHERE FilterField=@Filter)
            

            END

            Thanks.

            N Offline
            N Offline
            Niraj_Silver
            wrote on last edited by
            #5

            Hi.. Sure You Can Have This One....

            @Filter int,
            @theRows int output
            AS
            BEGIN
            SET @theRows=(SELECT Count(Field)
            FROM MyTable
            WHERE FilterField=@Filter)

            END

            Hope It Will work... do Reply.. Have Nice Day.. :-D

            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