Unix Technical Forum

Possible?: Count(*) returned by EXEC

This is a discussion on Possible?: Count(*) returned by EXEC within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi all, I have a stored procdure which does a select and returns the records directly -i.e. Not in ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 06:49 AM
James
 
Posts: n/a
Default Possible?: Count(*) returned by EXEC

Hi all,

I have a stored procdure which does a select and returns the records
directly -i.e. Not in output parameters e.g:

CREATE PROCEDURE up_SelectRecs(@ProductName nvarchar(30)) AS

SELECT *
FROM MyTable
WHERE [Name]=@ProductName

In another stored procedure I need to do the following:

SELECT COUNT(*)
FROM MyTable
WHERE [Name]=@ProductName

As the select queries are actually a lot more complex that this, I'd
rather not duplicate the select code in 2 sp's to save the maintenance
effort - I'm looking for a way to execute the first procedure from the
second and just count the records returned - something like:

SELECT Count(*)
FROM EXEC up_SelectRecs @ProductName

Any way to achieve this?

Thanks all

--James
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 06:49 AM
Simon Hayes
 
Posts: n/a
Default Re: Possible?: Count(*) returned by EXEC


"James" <Jamesmitchard@yahoo.co.uk> wrote in message
news:19d01a84.0501261535.1d7c6dd7@posting.google.c om...
> Hi all,
>
> I have a stored procdure which does a select and returns the records
> directly -i.e. Not in output parameters e.g:
>
> CREATE PROCEDURE up_SelectRecs(@ProductName nvarchar(30)) AS
>
> SELECT *
> FROM MyTable
> WHERE [Name]=@ProductName
>
> In another stored procedure I need to do the following:
>
> SELECT COUNT(*)
> FROM MyTable
> WHERE [Name]=@ProductName
>
> As the select queries are actually a lot more complex that this, I'd
> rather not duplicate the select code in 2 sp's to save the maintenance
> effort - I'm looking for a way to execute the first procedure from the
> second and just count the records returned - something like:
>
> SELECT Count(*)
> FROM EXEC up_SelectRecs @ProductName
>
> Any way to achieve this?
>
> Thanks all
>
> --James


See here:

http://www.sommarskog.se/share_data.html

If you have SQL 2000 (you didn't mention which version you have), a
table-valued UDF would probably work well in your case:

select * from dbo.MyFunc(@ProductName)
select count(*) from dbo.MyFunc(@ProductName)

Simon


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:54 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com