Monday, February 20, 2012

Multiple return

Hi,
I have one stored procedure with multiple selects, like this:
SELECT @.NumUsers = COUNT(*) ...
SELECT @.NumPages = COUNT(*) ...
Now it returns nothing, I suspected the count values.
I tried it with return... but then I only get one value.
How can I get the values as a table? With NumUsers and NumPages as
columnnames?
Thanks!hi,
SELECT @.NumUsers = COUNT(*) ...
SELECT @.NumPages = COUNT(*) ...
SELECT @.NumUsers As NumUsers, @.NumPages As NumPages
"Arjen" <boah123@.hotmail.com> wrote in message
news:ddpuls$upt$1@.news1.zwoll1.ov.home.nl...
> Hi,
> I have one stored procedure with multiple selects, like this:
> SELECT @.NumUsers = COUNT(*) ...
> SELECT @.NumPages = COUNT(*) ...
> Now it returns nothing, I suspected the count values.
> I tried it with return... but then I only get one value.
> How can I get the values as a table? With NumUsers and NumPages as
> columnnames?
> Thanks!
>|||Simple... ;-)
Thanks!
"arik" <arikf@.top4.com> schreef in bericht
news:%23qLX56YoFHA.2080@.TK2MSFTNGP14.phx.gbl...
> hi,
> SELECT @.NumUsers = COUNT(*) ...
> SELECT @.NumPages = COUNT(*) ...
> SELECT @.NumUsers As NumUsers, @.NumPages As NumPages
>
> "Arjen" <boah123@.hotmail.com> wrote in message
> news:ddpuls$upt$1@.news1.zwoll1.ov.home.nl...
>|||Hi
It would be better to return them as output parameters as there will be less
overhead in doing so. See the topic "Returning Data Using OUTPUT Parameters"
in Books online.
John
"Arjen" wrote:

> Simple... ;-)
> Thanks!
>
>
> "arik" <arikf@.top4.com> schreef in bericht
> news:%23qLX56YoFHA.2080@.TK2MSFTNGP14.phx.gbl...
>
>|||You can use OUTPUT parameters or a simple resultset.
CREATE PROCEDURE dbo.foo1
AS
BEGIN
DECLARE @.NumUsers INT, @.NumPages INT
SELECT @.NumUsers = COUNT(*) ...
SELECT @.NumPages = COUNT(*) ...
SELECT NumUsers = @.NumUsers, NumPages = @.NumPages
END
GO
CREATE PROCEDURE dbo.foo2
AS
@.numPages INT OUTPUT,
@.numUsers INT OUTPUT
BEGIN
SELECT @.NumUsers = COUNT(*) ...
SELECT @.NumPages = COUNT(*) ...
END
GO
Using the resultset is more code in the procedure (and more expensive
resource-wise) but simpler to deal with in the caller. Using Output
parameters makes the procedure itself smaller and lighter, but is a bit more
cumbersome to code from the caller.
A
"Arjen" <boah123@.hotmail.com> wrote in message
news:ddpuls$upt$1@.news1.zwoll1.ov.home.nl...
> Hi,
> I have one stored procedure with multiple selects, like this:
> SELECT @.NumUsers = COUNT(*) ...
> SELECT @.NumPages = COUNT(*) ...
> Now it returns nothing, I suspected the count values.
> I tried it with return... but then I only get one value.
> How can I get the values as a table? With NumUsers and NumPages as
> columnnames?
> Thanks!
>

No comments:

Post a Comment