.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Count how many rows are returned from a stored procedure

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :Sql Server
Hi,   I have written a stored procedure for my database which takes two varchar parameters and returns lots of rows of data. This data will be passed back to my .NET application with a reader for parsing.   Imagine this scenario of calling a stored procedure:   MyDatabase.dbo.sp_MyStoredProcedure 'String 1', 'String 2'   Let's say that this command returns 12,434 rows of data when executed in SQL Server Management Studio Express containing the data of 5 joined tables which contains 2 or 3 unions (depending on the input of 'String 2') and the data within each union is correctly sorted.   How do I get a row count from the execution of the above stored procedure command? I need to pass this back to my application for the progress bar to function correctly.   I don't want to replicate the function and modify it for counting rows because the stored procedure consists of approximately 150 lines of SQL code.   Thanks in advance.   Sean

View Complete Post

More Related Resource Links

Inserting rows via stored procedure and under certain conditions


I'm using Dynamic Data with Entity Framework in VS2010.

Let's say my table has these fields:

PersonID (FK)
LocationID (FK)

Hypothetical scenario (it's easier for me to explain this way, so just bear with me for now)... But let's say each row in the table represents "how many items were sold by such-and-such employee at such-and-such location," where location and person are foreign keys which are referencing other tables.  Basically, there should be no more than a ONE row which has a particular combination of Person and Location.  Makes sense?

So, when inserting new rows using my Dynamic Data app, the insert form displays editable fields for Person (dropdown), Location (dropdown), and Items Sold (textbox).  How do I prevent users from inserting another row into the table containing an already-existing combination of Person and Location?   How do I displaying useful feedback to them in the event that they DO attempt to do this?

I have several thoughts about this, but since I'm new to Dynamic Data, I'm not sure which way to go.  For example:

Option 1:  Use "cascading dropdowns" approach in the insert form and only pull in the "allowed" combinations of the two dropd

Using the BDC API how to catch the returned code when executing a stored procedure?

using BDC API, how can i catch the return code a stored procedure returns?

I tried Entity.Execute to execute a generic method. However, it returns an empty Entity table.

I know you can do it by setting up an output variable. I prefer returning an integer for tracking errors.

Any ideas?



How do we redirecting rows using stored procedure

Hi I have one SQL Execute task and it runs one stored procedure inside it. That SP inserts data into one of table.Now when I inserts records into this tbale let's say because of primary key some records are failing so how can i redirect this rows in stored procedure  

How can I replace values in GridView returned from a Stored Procedure

I am working on creating a stored procedure that will output a pivot table.  In the pivot table will be either the string NULL or a number.  How can I reformat this in ASP.NET so the NULL value becomes a blank cell in the gridview and the number (whatever it is) becomes an 'X' ?

count records from the same stored procedure SP (SQL2000)

i wish to create a task if there is any record from that SP, and then run The SP return list of records. My question is how to count records on SP? i find this solution (http://www.sqldev.org/transactsql/how-to-return-count-from-same-stored-procedure-which-is-used-for-pagination-73308.shtml) but my SQL is SQL2000 which does not support WITH clause. Thans a lot.

Performance of a Stored procedure : Optimum number of rows to be handled in a batch


In a stored procedure is there anything called as optimum number of rows that need to be handled in a batch

as In, If there is a SP,

   that picks up data(via union operation) from various objects and puts them into a temp table after which the required data is moved to various tables,The above scenario is handled as a batch run where in 1 million rows are processed in a batch and the next 1 million rows in a next batch,so on and so forth.

   Is there any optimum number of rows that can be processed in the above case?

  When we increase rows processed per batch we have seen improvements in performance of the SP,but not sure when it will start deteriorating.




Stored procedure help (group by, sub queries, count etc...)


Hi There,

im writing a stored procedure.... Given a groupID, i want to get all the groups from the groups table and also two extra columns....

the first extra column is UserCount, this goes off to the user's table and pulls out a user count for the group.

the second extra column is GroupCount. This goes away and pulls out all other groups that have a ParentID as the incoming org.

I know the stored procedure I have supplied isn't correct, im suspecting I need to have sub queries and group by's.... but sql isn't my forté.

The reason I need these properties returned this way is so that LinqToSql can create a custom object based on this return.

ALTER PROCEDURE [dbo].[uspGetTreeViewGroups]
	-- Add the parameters for the stored procedure here
	@GroupID int

				   WHERE u.GroupID = @GroupID
				   AND u.Enabled = 1) as UserCount,
				   (SELECT COUNT(*) FROM tblGroup g
					WHERE g.ParentID = @GroupID) as ChildCount
	FROM tblGroup g



stored procedure "need to take count from same table with different condition"

i have a stored procedure with few variable ,and in each variable i am taking count from same table based on different condition.and also i need to group by it on base of date(monthly wise
but if i declare thevariable and set value in it, then on dispalying these variable i get same value for all the months ..i am sending some part of it..please if possible make the changes and let me know where am i making mistake..







How to Get the Execution Count of a Stored Procedure?

How to Get the Execution Count of user define Stored Procedure?Basically i want to find the unwanted/un-using stored procedure in mssql.im using 2008 sql server.

Getting multiple rows from oracle stored procedure and binding it to grid view



To  get this stuff you need to create a Ref Cursor to return recordset.

             create or replace PACKAGE Types AS

            TYPE cursor_type IS REF CURSOR;

            END Types;

Now create a stored procedure to return multiple rows .

           create or replace

           PROCEDURE getAllCity(p_recordset OUT types.cursor_type) AS


           OPEN p_recordset FOR


Send Email from SQL Server Express Using a CLR Stored Procedure

One of the nice things about SQL Server is the ability to send email using T-SQL. The downside is that this functionality does not exist in SQL Server Express. In this tip I will show you how to build a basic CLR stored procedure to send email messages from SQL Server Express, although this same technique could be used for any version of SQL Server.

If you have not yet built a CLR stored procedure, please refer to this tip for what needs to be done for the initial setup.

Creating A Stored Procedure Which Searches Team Names



I'm have on my web page a text search box which I want users to type in there favourite football team and this will display a gridview of the teams with the replica shirts I offer.

This is where I thought about creating a stored procedure to carry out this task.

I looked online for ideas but I not found anything as yet.

If anyone done anything similar to my request please let me know.

Sort by gridview SortExpression parameter via Stored Procedure


I have a gridview that calls data via a stored procedure.  I am unable to enable the gridview columns to be sortable. I need to set the parameter in the Stored Procedure, can someone help me with this?

Here is my gridview:

<asp:GridView ID="AllUsersGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="UserName"
                        GridLines="Vertical" Width="900px" DataSourceID="SqlDataSource1" AllowSorting="True"
                        SelectedRowStyle-Height="30px" CellPadding="4" BackColor="White">
                            <asp:TemplateField HeaderText="Full Name" SortExpression="lastname">
                                    <asp:Label ID="DisplayName" runat="server" Text='<%# Eval("firstname").ToString() & " " & Eval("lastname").ToString() %>' />
                            <asp:BoundField HeaderText="User Name" DataField="UserName" />

Stored procedure generator?


Hi, I am looking for a stored procedure generator with full source code(C#) compatible with Visual studio 2010. I want to create my custom stored procedure code. Please send some link. Regards, ap.

Create stored procedure from asp.net



we are creating a custom report tool, which could be used for generate the report as per end user's needs. In that we are providing an option as user could create a query and procedure as well.

In sql server we can use "EXEC" function for execute dynamic query.

Could anyone help me for create the dynamic query in Oracle?

I just tried with "execute immediate", which would throws error as 

"insufficient privileges".

Please help me.



Call SQL Stored Procedure Asyncronously



I have a C# web page that calls a stored procedure. The page passes few parameters to the stored procedure and call it. The stored procedure does so many time consuming tasks on a huge number of database records but does not return any value.

Since the page is not expecting any return from the stored procedure, I want to execute the stored procedure asyncronously so that the user can continue working on the web page and other web pages while the stored procedure is running in the background. Also, I do not want the web server processes to be busy with the running stored procedure.

Any help, please.

Best regards,


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend