Results 1 to 3 of 3

Thread: Pass Schema into a stored procedure?

  1. #1

    Thread Starter
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Pass Schema into a stored procedure?

    OK, I have an application that can handle multiple site locations.
    These locations each need their own independent data, so our solution was to create a new schema for each site. I have created a group of stored procedures in the dbo schema. When a new site is created, I create a new schema and a new user with that schema as their default. I then give that user Execute permissions on the stored precedures. This all works great up to one point.

    I am able to create all the tables and their keys just fine, however I have a couple of tables that require some preinstalled data. I tried to have 2 procedures that contain insert statements, but for some reason, they are not being called against the default schema and are returning an error

    Is there a way to pass a schema name into a stored procedure and then insert it before the table name in the procedure? Or is there some other way to do this that would be easier? I have tried this a few ways and keep getting errors.

    Thanks for any help
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

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

    Re: Pass Schema into a stored procedure?

    Can you show a bit of what those procedures look like? We've never used schema level distinction here - maybe if you show me what you have I can offer a suggestion...

    *** 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
    Frenzied Member bmahler's Avatar
    Join Date
    Oct 2005
    Location
    Somewhere just west of the Atlantic
    Posts
    1,568

    Re: Pass Schema into a stored procedure?

    I was actually able to work around this, what I am doing is storing the procedures in the dbo schema and with each new schema we create, we make a login with that schema as it's default. I then se the Procedures to build the database, which worked fine and put the tables in that users default schema, however I was trying to do insert statements in a procedure, but it kept trying to insert into the dbo schema. I was able to work around this, by creating the common tables in the dbo schema and then just copying them to the new schema each time. It is working fine and is pretty quick as well. Thanks.
    Boooya
    • Visual Studio 2008 Professional
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • Don't forget to rate helpful posts!
    • If you're question was answered please mark your thread [Resolved]


    Code Contributions:
    PHP
    PHP Image Gallery v1.0PHP Image Gallery v2.0
    VB 2005
    Find Computers on a networkSimple License EncryptionSQL Server Database Access dllUse Reflection to Return Crystal ReportDocumentSilently Print PDFGeneric Xml Serailizer


    Useful Links: (more to come)
    MSDN (The first and foremost)MSDN Design Guidelines API Reference • Inno Setup CompilerInno Setup PreprocessorISTool - Fairly easy to use GUI for creating inno setup projects • Connection StringsNAnt -Automated BuildsCruise Control .NET - Frontend for automated builds

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