Results 1 to 28 of 28

Thread: [Resolved] Return value of Stored Procedure

  1. #1

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Resolved [Resolved] Return value of Stored Procedure

    Hi,

    Code:
    This is inside stored procedure
    ......
    Select @Result
    Return @Result
    ......
    Then i call this stored procedure from VB
    Code:
    with cm
    ......
    ......
    ......
    end with
    with rs
    ......
    ......
    .open cm
    msgbox .recordcount
    end with
    I got an error that "Operation is not allow when object is closed"
    I'm surely that i have open cm already, when i change to other
    stored procedure it works fine. I think the problem is i dont know
    how to use stored procedure which is using RETURN

    I have try this stored procedure in SQL analyzer, works fine.
    Can any one give me the right way to solve this problem?

    Thanks for advance
    Last edited by naruponk; May 5th, 2005 at 07:35 AM.

  2. #2
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Return value of Stored Procedure

    Are you doing anything else inside the proc before the SELECT @Result statement ie. inserts or updates?

    If so, try adding SET NOCOUNT ON as the first statement and see if that resolves the issue.

  3. #3

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    Same error.

    @Result is what i want, i have process it inside Stored Procedure
    no insert/update it is just select statement.

    One more question is how to exit Stored Procedure when it get some value and return a vlue together like Exit Sub, Exit Function?
    Last edited by naruponk; May 4th, 2005 at 07:22 AM.

  4. #4
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Return value of Stored Procedure

    To exit a Stored Proc use RETURN or RETURN (value) .

  5. #5

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    Code:
    with cm
    ......
    ......
    ......
    end with
    with rs
    ......
    ......
    .open cm
    msgbox .fields!Test
    end with
    This will be unknown fields even i type in stored proc that
    select @Result as Test.
    How to retreive a field from this stored procedure?

    Thanks Blade

  6. #6
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: Return value of Stored Procedure

    Are you able to post the whole stored proc?
    It might help us get to the problem faster if you can...

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Return value of Stored Procedure

    Looks to me like you are using a RECORDSET object and not a COMMAND object.

    You have no recordset coming back from the SPROC (from what I can tell by what you posted).

    Use the COMMAND object - execute the COMMAND to call the SPROC.

    The command object will contain the return parameters and any output parameters.

    We prefer to use output parameters - here's an example:

    Code:
    objCmd.CommandText = "AppConnect_Insert "
    objCmd.ActiveConnection = gCn
    objCmd.CommandType = adCmdStoredProc
            
    objCmd.Parameters.Append objCmd.CreateParameter("@RetConnId", adInteger, adParamOutput, 8)
    objCmd.Parameters.Append objCmd.CreateParameter("@RetOpenServTime", adChar, adParamOutput, 23)
    objCmd.Parameters.Append objCmd.CreateParameter("@ClientTime", adChar, adParamInput, 23 _
                                                                    , Format(Now, "yyyy-mm-dd hh:mm:ss.000"))
    objCmd.Parameters.Append objCmd.CreateParameter("@AppEXEName", adVarChar, adParamInput, 100, App.EXEName)
    objCmd.Parameters.Append objCmd.CreateParameter("@AppPath", adVarChar, adParamInput, 100, App.Path)
    objCmd.Parameters.Append objCmd.CreateParameter("@AppTitle", adVarChar, adParamInput, 100, App.Title)
    objCmd.Parameters.Append objCmd.CreateParameter("@AppComments", adVarChar, adParamInput, 100, App.Comments)
    objCmd.Parameters.Append objCmd.CreateParameter("@AppMajor", adInteger, adParamInput, 8, App.Major)
    objCmd.Parameters.Append objCmd.CreateParameter("@AppMinor", adInteger, adParamInput, 8, App.Minor)
    objCmd.Parameters.Append objCmd.CreateParameter("@AppRevision", adInteger, adParamInput, 8, App.Revision)
    objCmd.Parameters.Append objCmd.CreateParameter("@FLAGS", adVarChar, adParamInput, 100, "RES=[" & ScreenResolution & "]")
       
    objCmd.Execute
    
    glngConnId = objCmd.Parameters(0)
    gstrOpenServTime = objCmd.Parameters(1)

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Return value of Stored Procedure

    Here's the SPROC itself if you need to see what's going on in that...

    Code:
    --FIS
    Use Acctfiles
    SET QUOTED_IDENTIFIER ON 
    GO
    SET ANSI_NULLS ON 
    GO
    
    Drop Procedure AppConnect_Insert
    Go
    
    Create Procedure AppConnect_Insert 
    @RetConnId int OUTPUT
    , @RetOpenServTime char(23) OUTPUT
    , @ClientTime char(23)
    , @AppEXEName varchar(100)
    , @AppPath varchar(100)
    , @AppTitle varchar(100)
    , @AppComments varchar(100)
    , @AppMajor int
    , @AppMinor int
    , @AppRevision int
    , @Flags varchar(100)
    
    as
    
    Declare @ServerTime datetime
    DECLARE @Rollback int
    DECLARE @Count int
    Declare @HostName varchar(100)
    
    BEGIN TRAN
    
    Set @ServerTime = GETDATE()
    
    Set @Flags=IsNull(@Flags,'')
    Set @HostName='HOST=['+HOST_NAME()+']'
    If Len(@HostName)+Len(@Flags)<=100 Set @Flags=@HostName+' '+@Flags
    
    INSERT INTO AppConnect_T
    (UserID, OpenServTime, OpenClientTime, AppEXEName, AppPath
    ,AppTitle, AppComments,AppMajor, AppMinor, AppRevision
    , Status, Flags)
    Values
    (SYSTEM_USER, @ServerTime, @ClientTime, @AppEXEName, @AppPath
    , @AppTitle, @AppComments, @AppMajor, @AppMinor, @AppRevision
    , 'O', @Flags)
    
    Select @RollBack = @@error
    set @RetOpenServTime = Convert(Char(23),@ServerTime, 121)
    set @RetConnId = @@IDENTITY
    
    IF @Rollback <> 0
    BEGIN
    	ROLLBACK TRAN
    END
    ELSE
    BEGIN
    	COMMIT TRAN
    END
    
    GO
    
    GRANT EXEC ON AppConnect_Insert TO AcctfilesUser
    GO
    
    --Set @ident = @@IDENTITY
    
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    Thanks PilgrimPete,

    I think it is unneccessary to post whole stored proc.
    It is too much and need to use many of stored procedure together,
    also database.

    However I'm surely that the point is i might wrong to return a value
    Code:
    Select @Result
    Return @Result
    
    --this 2 lines is what i'm using

    I have try other stored procedure with one line of code inside stored procedure still get same error.
    you might try to create simple stored procedure which is using return keyword
    to return a values

    Thanks

  10. #10

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    Dear szlamany,

    Thanks for reply
    What does SET QUOTED_IDENTIFIER ON and SET ANSI_NULLS ON do?
    I can't run your Stored procedure cause i have no some of your stored procedure can you give me more shortly?

    Normally i use command to open recordset from stored procedure, works fine.
    but i can't open a recordset (using command) from stored procedure which is using RETURN keyword

    Thanks everyone
    Last edited by naruponk; May 4th, 2005 at 08:12 AM.

  11. #11
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: Return value of Stored Procedure

    OK. I have created a stored proc like this:
    Code:
    create proc test
    as
    declare @Result int
    
    set 	@Result = 99
    Select 	@Result
    Return 	@Result
    and called it like this:
    VB Code:
    1. private Const connString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=myDatabase;Data Source=myServer"
    2.  
    3. Private Sub Form_Load()
    4.     Dim cnn As ADODB.Connection
    5.     Dim cmd As ADODB.Command
    6.     Dim rst As ADODB.Recordset
    7.    
    8.     Set cnn = New ADODB.Connection
    9.     With cnn
    10.         .ConnectionString = connString
    11.         .Open
    12.     End With
    13.    
    14.     Set cmd = New ADODB.Command
    15.     With cmd
    16.         Set .ActiveConnection = cnn
    17.         .CommandType = adCmdStoredProc
    18.         .CommandText = "test"
    19.     End With
    20.    
    21.     Set rst = New ADODB.Recordset
    22.     With rst
    23.         .Open cmd
    24.         Debug.Print .Fields(0).Value
    25.     End With
    26. End Sub
    and I get 99 output to the debug window. I'm still none the wiser
    Sorry.

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Return value of Stored Procedure

    Nargh... Either SELECT the value or RETURN it... no need to do both...
    OK, now, to get the RETURN value of a stored proc, it goes like this:

    VB Code:
    1. cmd.Parameters.Append cmd.CreateParameter("@ReturnValue",adInteger,[b]adParamReturnValue[/b])
    Creating & setting this as the first parameter in your list should do the trick. The @ReturnValue can be anything as long as it's different from the other parameter names. After .Executing the command, you can get the value just like any other output parameter.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Return value of Stored Procedure

    Quote Originally Posted by techgnome
    Nargh... Either SELECT the value or RETURN it... no need to do both...
    This is really good advice - as was adding the SET NOCOUNT ON - which is one of our SQL Rules to Live by.

    RECORDSET data and output parameter data is in two different objects in ADO - and they cannot be touched at the same time.

    You have to process RS, then look at output parameters, then look at RS (if you have more than one RECORDSET in the SPROC), then look at output parameters again.

    SET NOCOUNT ON will make sure that the annoying "1 row affected" message doesn't get in the way of RECORDSET processing or output parameter processing.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  14. #14
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Return value of Stored Procedure

    Quote Originally Posted by naruponk
    Dear szlamany,

    Thanks for reply
    What does SET QUOTED_IDENTIFIER ON and SET ANSI_NULLS ON do?
    I can't run your Stored procedure cause i have no some of your stored procedure can you give me more shortly?

    Normally i use command to open recordset from stored procedure, works fine.
    but i can't open a recordset (using command) from stored procedure which is using RETURN keyword

    Thanks everyone
    Another one of our rules is to SCRIPT all DB objects in TEXT FILES that end in .SQL and execute them in QUERY ANALYZER to load them into the database.

    That SET QUOTED stuff is just boilerplate that we have in our SCRIPT files - something we saw that MS did in their scripts.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  15. #15
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: Return value of Stored Procedure

    Quote Originally Posted by szlamany
    Originally Posted by techgnome
    Nargh... Either SELECT the value or RETURN it... no need to do both...
    This is really good advice - as was adding the SET NOCOUNT ON - which is one of our SQL Rules to Live by.

    RECORDSET data and output parameter data is in two different objects in ADO - and they cannot be touched at the same time.

    You have to process RS, then look at output parameters, then look at RS (if you have more than one RECORDSET in the SPROC), then look at output parameters again.

    SET NOCOUNT ON will make sure that the annoying "1 row affected" message doesn't get in the way of RECORDSET processing or output parameter processing.
    I agree totally... I was just trying to answer what I thought was a hypothetical question, and to prove that given the posted code, it would actually work.
    I'd never actually advocate the use of a recordset to return a single value; though I generally lean towards using an output parameter to return data values, and save the adParamReturnValue parameter to return the success (or otherwise) of my proc - not least because you are restricted to returning ints in a RETURN statement. However, that's just down to personal taste and coding standards I guess...

  16. #16

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    Thanks a lot for help guys

    Even i set Return @Result at a first line of Stored Procedure
    I still getting same error "....When object is closed"
    The problem might be my Stored Procedure

    Code:
    Decalre @Result
    
    SET @Result=99
    Return @Result
    
    ........ below is too much of proceed ...........
    ............................................................
    If my Stored Procedure is look like this the process will end at
    Return @Result?

    Can i use Return keyword without select keyword before?

    I have found that after EXECUTE Other_StoredProc
    I will unable to open a recordset even i use select keyword,
    so .... how can i retrive a recordset?
    Last edited by naruponk; May 4th, 2005 at 11:09 PM.

  17. #17
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: Return value of Stored Procedure

    If you have a return statement at the top of your procedure, then it will do just that: Return.
    Nothing after the 'Return' will get executed. So, in your latest example there is no recordset created, so none will be returned.

    In order to get at your return value, you'll need to use the example that techgnome posted.

    I'm still not sure why you want a recordset and a return parameter containing the same value...

  18. #18

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    I'm still not sure why you want a recordset and a return parameter containing the same value...
    I just want to be able to retreive a value which is return from stored procedure and using ADO to retreive it. (Return value is after execute Other_StoredProc line in Stored Proc)


    Originally Posted by techgnome
    cmd.Parameters.Append cmd.CreateParameter("@ReturnValue",adInteger,adParamReturnValue)
    I try your code but i got another error "Formal parameter @Result was defined as OUTPUT but the actual parameter not declared OUTPUT."

    Can you tell me how should i declare a variable in my stored procedure
    to able to return a value by using ADO

    Thanks everyone

  19. #19
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: Return value of Stored Procedure

    Something like this:
    Code:
    create proc test
    as
    declare @Result int
    
    set 	@Result = 99
    Return 	@Result
    VB Code:
    1. private Const connString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=myDatabase;Data Source=myServer"
    2.  
    3. Private Sub Form_Load()
    4.     Dim cnn As ADODB.Connection
    5.     Dim cmd As ADODB.Command
    6.  
    7.    
    8.     Set cnn = New ADODB.Connection
    9.     With cnn
    10.         .ConnectionString = connString
    11.         .Open
    12.     End With
    13.    
    14.     Set cmd = New ADODB.Command
    15.     With cmd
    16.         Set .ActiveConnection = cnn
    17.         .CommandType = adCmdStoredProc
    18.         .CommandText = "test"
    19.         .Parameters.Append cmd.CreateParameter("@ReturnValue",adInteger,adParamReturnValue)
    20.         .Execute Options:=adExecuteNoRecords
    21.         Debug.Print .Parameters(0).Value
    22.     End With
    23.  
    24.     cnn.Close
    25.     Set cmd = Nothing
    26.     Set cnn = Nothing
    27. End Sub
    Quote Originally Posted by naruponk
    Can you tell me how should i declare a variable in my stored procedure to able to return a value by using ADO
    You don't need to declare an output parameter if you are using a return value. This proc will do the same as the previous one:
    Code:
    create proc test
    as
    -- do absolutely nothing, then return 99
    Return 	99

  20. #20

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    More better

    I got an error that "Arithmetic overflow converting expression to data type smalldatetime"

    My stored procedure is requires 3 parameter.
    1. @A bigint,
    2. @B smalldatetime
    3. @C smalldatetime

    Code:
    Set cmd = New ADODB.Command
    With cmd
    Set .ActiveConnection = cnn
    .CommandType = adCmdStoredProc
    .CommandText = "WN1_GetIFNPV"
    .Parameters.Append .CreateParameter("@A", adBigInt, adParamReturnValue)
    .Parameters.Append .CreateParameter("@A", adBigInt, adParamInput, , 1)
    .Parameters.Append .CreateParameter("@B", adDate, adParamInput, , "04/04/2005")
    .Parameters.Append .CreateParameter("@C", adDate, adParamInput, , "04/04/2005")
    .Execute Options:=adExecuteNoRecords
    Debug.Print .Parameters(0).Value
    End With
    How should i give parameters as correct format?

  21. #21
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: Return value of Stored Procedure

    I'm not sure really - I generally use datetime, not smalldatetime, but you might try adDBDate instead of adDate to see if that helps.

    [BTW I wouldn't call your return parameter the same thing as your first input parameter.]

  22. #22

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    [BTW I wouldn't call your return parameter the same thing as your first input parameter.]
    Did you mean i should remove .Parameters.Append .CreateParameter("@A", adBigInt, adParamInput, , 1) ?

  23. #23
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: Return value of Stored Procedure

    Well. It depends. You can remove it - but you'll also need to remove it from the stored procedure, or just rename it like this:
    VB Code:
    1. .Parameters.Append .CreateParameter("RETURN", adInteger, adParamReturnValue)
    2. .Parameters.Append .CreateParameter("@A", adBigInt, adParamInput, , 1)
    3. .Parameters.Append .CreateParameter("@B", adDate, adParamInput, , "04/04/2005")
    4. .Parameters.Append .CreateParameter("@C", adDate, adParamInput, , "04/04/2005")
    ...but it depends on how you are using it really.

  24. #24

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    "Arithmetic overflow converting expression to data type smalldatetime"

    I'm using a code which i posted really.

    Code:
    Parameters.Append .CreateParameter("RETURN", adInteger, adParamReturnValue)
    Is return value should be 1st parameter?

  25. #25

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    I have create new stored proc which is requires 1 parameter only (@A)

    VB Code:
    1. .Parameters.Append .CreateParameter("@A", adBigInt, adParamInput, , 1)
    2. .Parameters.Append .CreateParameter("@Result", adBigInt, adParamReturnValue)

    above code will give me that ""Stored Proc ... has too many agrument specific"


    VB Code:
    1. .Parameters.Append .CreateParameter("@Result", adBigInt, adParamReturnValue)

    This will give me that " ... @A not supplied"
    Am i giving incorrect format?

  26. #26
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Return value of Stored Procedure

    I'm pretty sure that the RETURN {int} T-SQL command does not return that value in the PARAMETER collection.

    I cannot find backup for this in MSDN - I've got a good ADO book at work that I'll check in 30 minutes...

    Why are you so stuck on using RETURN {int} and not simply creating a list of INPUT and OUTPUT parameters? My example showed how to do that quite easily.

    The error you keep saying you are getting sounds more like a VB/ADO side error - that the object is not properly created and the SPROC isn't even executing.

    BTW - we decided at the start of our development project in VB/ADO/SQL that using LONG (VB) and INT (SQL) was the only integer style we would support. DATETIME also - no small datetime. Supporting lots of different datatypes in the PARAMETER logic is too complex.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  27. #27
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313

    Re: Return value of Stored Procedure

    Quote Originally Posted by szlamany
    I'm pretty sure that the RETURN {int} T-SQL command does not return that value in the PARAMETER collection.

    I cannot find backup for this in MSDN - I've got a good ADO book at work that I'll check in 30 minutes...

    Why are you so stuck on using RETURN {int} and not simply creating a list of INPUT and OUTPUT parameters? My example showed how to do that quite easily.

    The error you keep saying you are getting sounds more like a VB/ADO side error - that the object is not properly created and the SPROC isn't even executing.

    BTW - we decided at the start of our development project in VB/ADO/SQL that using LONG (VB) and INT (SQL) was the only integer style we would support. DATETIME also - no small datetime. Supporting lots of different datatypes in the PARAMETER logic is too complex.
    I agree with the OUTPUT parameters idea szlamany - sorry missed that bit in your previous post when I posted this:
    Quote Originally Posted by PilgrimPete
    ...though I generally lean towards using an output parameter to return data values, and save the adParamReturnValue parameter to return the success (or otherwise) of my proc...
    naruponk - the adParamReturnValue parameter has to be the first you add to the parameters collection in the VB code, otherwise you will get the error you report.

  28. #28

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Return value of Stored Procedure

    Ok .... look works
    Thanks for ideas & helps guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width