Loading ...
Sorry, an error occurred while loading the content.

Re :MUGH-SQLCON Access data on another Server

Expand Messages
  • ravindhar Bonagiri
    Koushik,     Try with this:            strSQL = SELECT * FROM
    Message 1 of 1 , Mar 28, 2008
      Koushik,     Try with this:            strSQL = "SELECT * FROM " + @ServerName + " .[databasename].dbo.tablename "            exec strSQL             Needless to say @ServerName  server should be a linked server on the server you are              trying this query.       Let me know if you still have problems.Thanks,RaviOn Tue, 25 Mar 2008 21:46:08 -0700 (PDT) sqlcon@yahoogroups.com wroteHi Team,I have a need to access data on another server in astored proc and as long as I hard code the servername, it works, but I want to have the server name asa variable since it will change when we move fromDevelopment to Production. Example of hard coded server name:select * from [servername\instancename].[databasename].dbo.tablenameI am trying to get this to work:DECLARE @ServerName varchar(255)SET @ServerName = '[servername\instancename]'select * from @ServerName.[databasename].dbo.tablenameLet me know if you have any ideas as to how I can getthis to work. I have tried a "use" command, but it isonly for database (not servers).Appreciate for your help.__________________________________________________________Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.