SQL server linked server, Quering remote server instance with \ in it name

Newtojob 46 Reputation points
2024-09-23T23:53:40.1366667+00:00

Hi All,

I need to query a SQL server linked server with \ in the name like Server name \instancename.

when I use [linkedservername].[db].[Schemaname].tablename then receiving an error.

Error : msg 117 level 15, State 1 procedure

'DBSourceServer.SourceDWHTemp.dbo.SourceTable1' contains more than the maximum number of prefixes. The maximum is 2

If I remove square brackets then receiving another error.

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near  \

is there a way to address this issue. I cannot change the linked server name.

Please advise.

Thank you

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,866 questions
{count} votes

2 answers

Sort by: Most helpful
  1. LiHongMSFT-4306 27,101 Reputation points
    2024-09-24T02:00:35.1133333+00:00

    Hi @Newtojob

    Generally, SQL Server support four-part name in the form like this:

    SELECT * FROM [LinkedServerName].[DatabaseName].[SchemaName].[TableName];
    

    However, the error message says the maximum value is 2.

    Guess that you're using the SELECT - INTO Clause, because it is not supported to create new table on a remote server.

    Try this:

    INSERT INTO [LinkedServerName].[DatabaseName].[SchemaName].[TableName]
    SELECT * FROM [LocalServerName].[DatabaseName].[SchemaName].[TableName]
    

    Alternatively, you can use the OPENQUERY function or the OPENDATASOURCE function in the FROM clause to specify the remote data source.

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


  2. Olaf Helper 44,816 Reputation points
    2024-09-24T05:22:03.0166667+00:00

    contains more than the maximum number of prefixes. The maximum is 2

    Then I guess you uses Azure SQL Database?

    Azure DB don't support cross server/cross database access.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.