Results 1 to 3 of 3

Thread: Accessing Standard Procedures that are functions via VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    5

    Accessing Standard Procedures that are functions via VB

    Hello,

    I'm having trouble figuring out how to resolve my current issue with accessing the result of a stored procedure. The stored procedure is a function and returns a text value (the function itself returns the value, NOT via parameter). Everything I've read online deals with attaching a stored procedure that returns a record set and traversing the results or reading an output parameter that was passed. These procedure's are third party so I don't have the option of adding an output parameter and placing my return value in there.

    Any thoughts?

    thanks
    brad

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

    Re: Accessing Standard Procedures that are functions via VB

    Is it a stored procedure or is it a user-defined function - you say both.

    My first thought is that a stored procedure can only RETURN a numeric value. Any text being passed back need to come back in the form of OUTPUT PARAMETERS.

    OUTPUT parameters have problems of their own. If a recordset is also returned from the SPROC, then it must be read fully before the OUTPUT parameters appear - ADO is very sequential in this area...

    How are you calling the SPROC or UDF right now??

    Here's a code snippet I dug up for returning a UDF value as a RECORDSET - if that's what you are doing.

    Code:
        rs.Open "SELECT dbo.GetConf('" & ConfItem _
            & "') as ConfData", gCn
        GetConf = rs!ConfData & ""
    Otherwise here is some ADO for calling a SPROC and looking at OUTPUT parameters - there is no recordset returned by these SPROCS (and they use SET NOCOUNT ON at the top of each SPROC to avoid ADO issues with "RECORDSET AFFECTED" output data).

    Code:
        With objCmd
            .CommandText = s1
            .ActiveConnection = gCn
            .CommandType = adCmdStoredProc
            
            .Parameters.Append .CreateParameter("@PassConnId", adInteger, adParamInput, 8, glngConnId)
            .Parameters.Append .CreateParameter("@RetStat", adInteger, adParamOutput, 8)
            .Parameters.Append .CreateParameter("@RetText", adVarChar, adParamOutput, 100)
            .Parameters.Append .CreateParameter("@RetMode", adInteger, adParamOutput, 8)
            .Parameters.Append .CreateParameter("@RetGrid", adInteger, adParamOutput, 8)
            .Parameters.Append .CreateParameter("@RetExtra", adVarChar, adParamOutput, 100)
            .Parameters.Append .CreateParameter("@PassMode", adInteger, adParamInput, 8, f.mintFormState)
            .Parameters.Append .CreateParameter("@PassExtra", adVarChar, adParamInput, 10, strSaveExtra)
            .Parameters.Append .CreateParameter("@PassTest", adChar, adParamInput, 1, "")
            
            .Execute
            lngUpdCnt = lngUpdCnt + 1
        End With
    
        Debug.Print "       SaveGrid>@RetStat="; objCmd.Parameters(1).Value
    
        Select Case CLng(objCmd.Parameters(3).Value)
            Case Is > 0
                SaveGrid = CLng(objCmd.Parameters(3).Value)     ' @RetMode
            Case Is = -1
                strErrMsg = objCmd.Parameters(2).Value
        End Select

    *** 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

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2003
    Posts
    5

    Re: Accessing Standard Procedures that are functions via VB

    Thanks for the response.

    I'm actually calling an Oracle package they've provided. If I'm in SQL Plus and make the call the result is a bunch of text.

    Because it's their package I using a parameter for output is not any option.

    Any thoughts?

    -brad

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