Re: Stored Procedure, Output Value with SELECT Statement

From: Ross McKay (rosko_at_zeta.NOT.THIS.BIT.org.au)
Date: 03/08/04


Date: Mon, 08 Mar 2004 07:47:06 GMT

G'day SK,

See modifications inline:

>ALTER PROCEDURE OutputMyValue
>(
> @ValueToBeOutput bit OUTPUT
>)
>AS
>BEGIN

   Set NoCount On

> SELECT * FROM MyTable WHERE id = '123'
>
> SET @ValueToBeOutput = 1
>
>END
>
>How to resolve this? If I want both the output value and the select statements values to be returned?

First, you are best off with the Set NoCount On in your procedure.

Next, your output parameter will only be available to your client code
after you have read all of the select cursor on your client connection.
This is because the output parameters are at the end of the data stream
coming from SQL Server.

Choices:

a) do what you need with the cursor / recordset first, then look at
parameter

b) load the recordset into an array or something so that you can get to
the parameter

c) open the cursor as a client-side recordset, not server-side:

        rs.CursorLocation = adUseClient
        rs.Open cmd ' cmd is a command object;
        ' or alternatively,
        rs.Open "OutputMyValue", db_connection, , adCmdStoredProc

I'd recommend option c)

regards,
Ross.

-- 
"There is more to life than simply increasing its speed." - Mahatma Gandhi


Relevant Pages

  • Re: Slim Jim
    ... Depending on your stored proc uou might also have to use the NoCount option ... SET NOCOUNT OFF ... >> returned from the stored procedure into the recordset... ... > only cursor by default which does not support the RecordCount property. ...
    (microsoft.public.excel.programming)
  • Re: Mapping Output Parameters to DTS Global Variables
    ... So add SET NOCOUNT ON to the top of the SQL Execution Step. ... > I have tried using an Output Parameter in the SP but that didn't work ... It seems to regard the columns of a returned rowset as ...
    (microsoft.public.sqlserver.dts)
  • Re: SPs which return one value
    ... that returning it as an output parameter is a hair faster. ... > In all of the above examples, the SPs could simply return a recordset ... and interrogate dr.ToStringor whatever. ... > ExecuteScalar be more efficient than ExecuteReader, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: aout cursor staoed procedure and vb6 (ado)
    ... I correct stored procedure name of prefix ... cursor on runing row by row. ... > 2) The RETURN value is not an OUTPUT parameter. ... >> DECLARE curBsDetail CURSOR FOR ...
    (microsoft.public.data.ado)
  • Re: Command Object Output Parameter Undefined?
    ... understanding how my command object is behaving. ... connection object, then I create 2 input and one output parameter. ... Why would capturing the returned recordset ...
    (microsoft.public.data.ado)