CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2005
    Posts
    158

    Dynamic DB Selection

    I'm using SQL Server 2000 and am looking for a way to dynamically select which database to select from in a stored procedure.

    I have 4 possible DBs to choose from and don't want to write 5 SPs: 1 to choose which DB and 1 for each DB, simply changing the [db].dbo.tableName, know what I mean.

    I'm aware of the exec('SELECT * FROM [db].dbo.tableName') option, but I'm looking for a (hopefully) easier solution.

    Something like SELECT * FROM @myDB.dbo.tableName (which doesn't work).

    Anyone have any suggestions?

  2. #2
    Join Date
    Sep 2004
    Posts
    65

    Re: Dynamic DB Selection

    I would use dynamic sql string. Just build the sql as a string and execute all within your stored procedure.

  3. #3
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

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

Featured