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
 General SQL Server Forums
 New to SQL Server Programming
 How many records a stored procedure returns?

Author  Topic 

1sabine8
Posting Yak Master

130 Posts

Posted - 2007-10-11 : 05:05:37
Hi,
I need to know whether a stored procedure returns only a single record or it can return more than one if the query if for example to return all records in a specific date range.
Thanks.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-11 : 05:08:50
It can return as many records as you want.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-11 : 05:12:34
[code]Select count(*)
from OPENROWSET('SQLOLEDB','Data Source=MyServer;Trusted_Connection=yes;Integrated Security=SSPI', 'Execute DB1..MyProc1')[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-11 : 05:28:27
Execute DB1..MyProc1
select @@RowCount as returnedRows

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2007-10-11 : 05:29:39
If you're thinking about processing at the client side, e.g in .NET , you return the recordset as an object and then iterate through the recordset in your application

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com/SQL
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-11 : 05:49:53
quote:
Originally posted by spirit1

Execute DB1..MyProc1
select @@RowCount as returnedRows

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com



Spirit1,

That wont work unless SELECT is really the last statement in the proc. Lets say there is some temp table processsing like this.

Create Table #temp
(
...
)

set nocount on

Insert #Temp
select * from SomeTable

-- do some processing on temp table here
....

select * from #temp

drop table #temp
GO


then

SELECT @@ROWCOUNT


wil return 0 no matter what is the result of SELECT statement.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-11 : 05:51:57
true.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -