Results 1 to 8 of 8

Thread: Multiple Stored Procedures

  1. #1

    Thread Starter
    Lively Member jkmcgrath's Avatar
    Join Date
    Dec 2004
    Posts
    79

    Multiple Stored Procedures

    Hi,

    The stored procedures used in my code is mounting, now I find myself having to create mulitiple recordsets and command objects. Some of these require parameters and a couple do not.

    EXECUTE sp_xxxxx for each stored procedure wrapped up in a single stored procedure is what I was looking at so that I could change each sproc as needed and use it in other places in my code.

    The question is how would I go about passing parameters to those sprocs wrapped up in the sproc or is there a better way?

    This is with vb6 w/sp6 and MSSQL 2k w/sp4.

    Thanks
    John
    Just an infant in VB years

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

    Re: Multiple Stored Procedures

    BTW - you should not name your SPROCS with sp_ as the prefix, as that causes the SQL ENGINE to see if a system sproc with name exists in the MASTER database.

    We use this stored procedure:

    Code:
    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
    To tell us what parameters, data_types, lengths exist for a given stored procedure.

    We have a general routine for calling all our stored procedures that first calls this SPROC to see what is needed to call the stored procedure in question.

    We then have a general "bind" routine that binds the VB variables/controls/arrays - whatever - to the parameters in the stored procedure.

    Also - are you aware that a stored procedure can return many, many recordsets?

    After 4 years of VB/MS SQL development we are up to around 1000 or so stored procedures for our three major business applications.

    Never once in our VB app do we call these SPROCS specifically - we always use the methods described above.

    *** 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
    Lively Member jkmcgrath's Avatar
    Join Date
    Dec 2004
    Posts
    79

    Re: Multiple Stored Procedures

    Thanks szlamany I will rename those.

    Multiple select statements in a single sproc if that is what you are referring to?

    Here is the code in procedure that pulls the sproc..
    VB Code:
    1. 'rs5******************************************************
    2.     Dim strDodaac As String
    3.     strDodaac = Trim(rs("dodac"))
    4.     Set objCMD_AD.ActiveConnection = oCon
    5.     objCMD_AD.CommandText = "sp_addr"
    6.     objCMD_AD.CommandType = adCmdStoredProc
    7.     objCMD_AD.Parameters.Append objCMD_AD.CreateParameter("@dodaac", adChar, adParamInput, 6, strDodaac)
    8.     Set rs5 = objCMD_AD.Execute
    9. 'rs6******************************************************
    10.     Dim strFrom As String
    11.     strFrom = Trim(rs3("DODAAC"))
    12.     Set objCMD_AD2.ActiveConnection = oCon
    13.     objCMD_AD2.CommandText = "sp_addr"
    14.     objCMD_AD2.CommandType = adCmdStoredProc
    15.     objCMD_AD2.Parameters.Append objCMD_AD2.CreateParameter("@dodaac", adChar, adParamInput, 6, strFrom)
    16.     Set rs6 = objCMD_AD2.Execute

    And here is where I put the declarations in a module with a sub to open the db..
    VB Code:
    1. 'MSSQL 2000 Connection
    2. Public oCon As New ADODB.Connection
    3. Public rs As New ADODB.Recordset
    4. Public rs3 As New ADODB.Recordset
    5. Public rs4 As New ADODB.Recordset
    6. Public rs5 As New ADODB.Recordset
    7. Public rs6 As New ADODB.Recordset
    8. Public rs7 As New ADODB.Recordset
    9. Public rs8 As New ADODB.Recordset
    10. Public rsIN As New ADODB.Recordset
    11. Public objCMD As New ADODB.Command
    12. Public objCMDIN As New ADODB.Command
    13. Public objCMD_SP As New ADODB.Command
    14. Public objCMD_AD As New ADODB.Command
    15. Public objCMD_AD2 As New ADODB.Command
    16. Public objParm As New ADODB.Parameter
    17. Public strSQL As String
    18. Public strCON As String

    To me it doesnt seem as though I am doing the best way or most effient way although it works

    Just hate doing things sub par.
    Just an infant in VB years

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

    Re: Multiple Stored Procedures

    Do you need rs5 and rs6 at the same time?

    Where to you put the data from the recordsets?

    We usually load them into flexgrids and immediately destroy the recordset.

    I don't see a problem with calling a SPROC with a different "lookup key" many, many times.

    We do use a single routine to call our SPROC though - so we simply pass the "lookup key" to the routine and it calls the SPROC.

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

  5. #5

    Thread Starter
    Lively Member jkmcgrath's Avatar
    Join Date
    Dec 2004
    Posts
    79

    Re: Multiple Stored Procedures

    Yes I need all the information at one time, What I have to do (or should I say the only I have been able to make it work the best so far) is have a form that has an "form" on it. To stack text on the form in the space provided i.e...
    2
    3
    I have to use print x = y = during the loading of the form, During design phase I draw lines with the lines and provide labels for the rest of the text. I have a module containing a sub procedure that populates the labels on the forms.

    So when I click "print" or "preview" the form is completed with all required data. (I am having to pull info from non RDBMS sources as well to complete this form)

    Inline SQL statements were mounting so I wanted to reduce overhead (all this is coming from the network involving 3 servers the users workstation and then a networked printer, sFTP) and move all Inline statements to sprocs.

    So I am at the point I still have the same number of recordsets but have equal number of command objects now which in my mind is creating more overhead for the creation of them. So I was trying to reduce the overhead of that process. There is a trip to the server for each one where I would like to reduce it to one and let the server process it once and send it once.

    The sFTP I cannot trim until my request for a dll from weonlydo is approved, the search of the non-RDBMS cannot be trimmed until I can devise a way to import 4gigs of data from a dvd into the MSSQL 2k server.

    So while some of the gains is small from the sprocs, every little bit is important for me at this point and the only areas I can improve is what I directly have control over and that is the sprocs, vb program and sql server.

    Not sure my ramblings make any sense
    Just an infant in VB years

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

    Re: Multiple Stored Procedures

    See post #10 in this thread:

    http://www.vbforums.com/showthread.p...=nextrecordset

    Actually, search for NEXTRECORDSET on the forum as well.

    SPROCS can return many recordsets - but they can only be processed on the client one at a time.

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

  7. #7

    Thread Starter
    Lively Member jkmcgrath's Avatar
    Join Date
    Dec 2004
    Posts
    79

    Re: Multiple Stored Procedures

    Roger that but these recordsets are from serveral different sprocs containing unique info.

    I would roll them up into one proc but each proc requires a parameter from the previous proc so guess that is where I have to find a solution is passing a parameter from my code to the first proc and then pass that parameter to the rest of the procs.
    Just an infant in VB years

  8. #8
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Multiple Stored Procedures

    Quote Originally Posted by jkmcgrath
    Roger that but these recordsets are from serveral different sprocs containing unique info.

    I would roll them up into one proc but each proc requires a parameter from the previous proc so guess that is where I have to find a solution is passing a parameter from my code to the first proc and then pass that parameter to the rest of the procs.
    Is this what you mean by passing the parameter to the rest of the sprocs?
    Code:
    create procedure MasterSproc @SomeParameter int
    as
    exec SubSproc1 @SomeParameter
    exec SubSproc2 @SomeParameter

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