TSQL to dynamically change SQL Server 2005 Connections in 1 script

  • Looking for sample TSQL to dynamically change SQL Server 2005 Connections in 1 script.. Example:

    --

    --Connect to SQL Server 1   <-- Need TSQL to do this

    --

    USE MyDB1

    GO

    SELECT TOP 1 * FROM CUSTOMERS

    --Connect to SQL Server 2   <-- Need TSQL to do this

    --

    USE MyDB3

    GO

    SELECT TOP 1 * FROM PARTS

     

     

    BT
  • You might consider using linked server connections then and dynamic SQL to specify the servername. I've even seen scripted sp_addlinkedserver commands, however that can get a pretty hairy pretty quickly.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply