changing servers

  • I'm trying to copy stuff from 1 server to another, but I dont want to hardcode the server string.  I'd like to do what I have below, but it wont work. Any ideas?

    DECLARE @server as varchar(100)

    SET @server = 'stageServer1'

    SELECT * FROM @server + '.database.tablename'

     

    Steven

  • Something like this should work:

    DECLARE @server as varchar(100), @sqltext as varchar(100)

    SET @server = 'stageServer1'

    set @sqltext = 'select top 10 * from ' + @server + '.[databasename].[owner].[tablename]'

    exec(@sqltext)

    Regards

    Phil

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

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

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