Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to query a table from another SQL Server on a different server but same domain, but I am not sure how I will be able to do it.

I tried the solution in this answer but it doesn't work for me as I got SQL Server 2000.

When I try solution given this sql command,

 SELECT * FROM [AnotherServer].[AnotherServerDatabase].Server.Table1

Then I get error,

Msg 7202, Level 11, State 2, Line 1 Could not find server 'AnotherServer' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

If I try command below on live database, would it effect any customer ?

EXEC sp_addlinkedserver @server='AnotherServer'
share|improve this question

closed as unclear what you're asking by Kin, Marian, swasheck, Mark Storey-Smith, Jon Seigel Jul 18 '13 at 16:25

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Um, can you show the whole command? Where is the - character? – Aaron Bertrand Jul 18 '13 at 15:47
If you show the command you are trying to run, we may be able to help you correct it. If we can't see the command, we can't tell you what's wrong. – Aaron Bertrand Jul 18 '13 at 15:48
@user13814 we have one line of code and that's been obfuscated. we are left to assume that the one line of code that you've given is "line 23" but we have no guarantees. could you please address the concern that the linked server has a "-" in its name? – swasheck Jul 18 '13 at 15:57
@user13814 The message error is a part of the question, we need to see the query you are using to really help you, we are not mind readers – Lamak Jul 18 '13 at 15:58
@user13814 I'm so confused now as to what you're asking and what error you're actually getting. Does the server name have a hyphen in its name? Please, just answer that one question. – swasheck Jul 18 '13 at 16:02
up vote 5 down vote accepted

I'm going to take a wild guess here, and the problem is not that your command is "not compatible" but rather that your linked server name, or database name, or table name contains a -. To fix this, you surround it with [square brackets].

CREATE VIEW dbo.viewname
  SELECT column_names_please_not_*
    FROM [AnotherServer].[AnotherServerDatabase].dbo.[Table1];

Of course, first, you need to have a linked server created and set up appropriately in terms of permissions.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.