Results 1 to 8 of 8

Thread: How to read SQL Stored Proc Data?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Question How to read SQL Stored Proc Data?

    I want to create a function that can read my stored procs parameters and return their names to me. I am using ADO.

    Is this possible?

    Thanks

  2. #2
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: How to read SQL Stored Proc Data?

    Hello jesus4u,
    Look Here
    Is that what you need?

    Best Regards,
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Re: How to read SQL Stored Proc Data?

    it might be thanks

  4. #4
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: How to read SQL Stored Proc Data?

    Hello again,
    Dont thank me its from the MSDN...

    Basically, when i search for (good) answers i start with MSDN
    Then i search through Google and when i know i'm stuck i go directly to VBForums.com to look for the answer.

    In VBForums i know i can find the answers to my questions and even more i know i will get few different answers onthe same question.


    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: How to read SQL Stored Proc Data?

    The link posted by eranfox shows you how to create and execute a command object.

    Here are two ways to retrieve information about the parameters of a stored procedure.

    VB Code:
    1. Dim rs As ADODB.Recordset
    2.     Dim cmd As ADODB.Command
    3.     Dim prm As ADODB.Parameter
    4.     Dim strConn As String
    5.  
    6.     strConn = "provider=sqloledb;data source=handel;initial catalog=northwind;integrated security=sspi"
    7.  
    8.    'get stored procedure parameter information using sp_sproc_columns system stored procedure
    9.     Set rs = New ADODB.Recordset
    10.     rs.CursorLocation = adUseClient
    11.     rs.Open "sp_sproc_columns 'CustOrderHist'", strConn, adOpenStatic, adLockReadOnly
    12.     Set rs.ActiveConnection = Nothing
    13.    
    14.     Do Until rs.EOF
    15.         Debug.Print rs.Fields("COLUMN_NAME").Value, rs.Fields("TYPE_NAME").Value, rs.Fields("LENGTH").Value
    16.         rs.MoveNext
    17.     Loop
    18.    
    19.     rs.Close
    20.  
    21.     'auto populate the command.parameters collection using the Refresh method.
    22.     Set cmd = New ADODB.Command
    23.     With cmd
    24.         .ActiveConnection = strConn
    25.         .CommandText = "CustOrderHist"
    26.         .CommandType = adCmdStoredProc
    27.         .Parameters.Refresh
    28.        
    29.         For Each prm In .Parameters
    30.             Debug.Print prm.Name, prm.Type, prm.Size
    31.         Next
    32.     End With

  6. #6
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: How to read SQL Stored Proc Data?

    Quote Originally Posted by eranfox
    Basically, when i search for (good) answers i start with MSDN
    Then i search through Google and when i know i'm stuck i go directly to VBForums.com to look for the answer.
    I do the opposite. I find MSDN lacking on good information. Or even if they do have it, it's scattered across 10 pages

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

    Re: How to read SQL Stored Proc Data?

    Do you mean that you want a SPROC that will tell you the parameters of a given SPROC in the database?

    Code:
    USE Stufiles
    GO
    SET QUOTED_IDENTIFIER ON 
    GO
    SET ANSI_NULLS ON 
    GO
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetSqlSP]') 
    and OBJECTPROPERTY(id, N'IsProcedure') = 1)
    drop procedure [dbo].[GetSqlSP]
    GO
    CREATE PROCEDURE GetSqlSP
    	 @StoredProc varchar(50)
    AS
    Select Parameter_Name,Data_Type,Parameter_Mode,Character_Maximum_Length
    From INFORMATION_SCHEMA.Parameters
    Where SPECIFIC_NAME = @StoredProc 
    Go
    GRANT EXECUTE ON GetSqlSP TO StufilesUser
    Go
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO
    --execute GetSqlSP 'frmContribution_View'

    *** 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
    Hyperactive Member eranfox's Avatar
    Join Date
    May 2001
    Posts
    492

    Re: How to read SQL Stored Proc Data?

    Quote Originally Posted by umilmi81
    I do the opposite. I find MSDN lacking on good information. Or even if they do have it, it's scattered across 10 pages
    Hello umilimi81,
    I think you did not notice the brackets on the word good regarding the search on the MSDN.
    ERAN
    Eran Fox
    ASSEMBLER,C,C++,VB6,SQL...

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