Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 row count from exec call

Author  Topic 

hog
Constraint Violating Yak Guru

284 Posts

Posted - 2006-02-15 : 09:51:13
I am trying to count the number of rows returned from an procedure call and get sytax errors.

exec MyStoredProc

returns all the rows and columns for another usage, but I can also include this in my next procedure to get the required count.

I have tried this and get errors so not sure if this is possible?

select count(item) from exec MyStoredProc

??




madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-15 : 09:54:26
One possible method is to make use of @@RowCount. Immediately after running that procedure, assign that count to a variable

Declare @count as integer
exec MyStoredProc
Select @count=@@RowCount
Select @count -- will have the row count that sp returns

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

hog
Constraint Violating Yak Guru

284 Posts

Posted - 2006-02-15 : 10:04:56
Oooo I was excited then, but I get zero?

The proc returns 2 rows but @Count = 0?
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-02-15 : 23:30:18
Check if select is the last statement to be executed in your stored procedure.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-16 : 01:59:28
quote:
Originally posted by hog

Oooo I was excited then, but I get zero?

The proc returns 2 rows but @Count = 0?


Post the full code you used

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -