How to reference a sql server with a backslash (\) in its name?

前端 未结 3 1822
说谎
说谎 2021-02-13 04:48

Givens:

  • One SQL Server is named: DevServerA
  • Another is named: DevServerB\\2K5

Problem:

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-13 05:29

    On SQL SERVER 2005, the following happened: Entry of:

    SELECT TOP 1 *   
    FROM [DevServerB\2K5].master.sys.tables 
    

    Is changed to

    SELECT TOP 1 *   
    FROM DevServerB\2K5.master.sys.tables 
    

    by SQL Server system and you still get the error message: Incorrect syntax near '.'.

    I tried it with a linked server named in two different ways: '[DevServerB\2K5]' and 'DevServerB\2K5'

    Does anybody have any other ideas?

    Thank you Alan Robertson

    CORRECTION added the next day: I was wrong, partially. When one tries to create a view using a SQL statement like:

    SELECT  *
    FROM [DevServerB\2K5].TestDB.dbo.tables 
    

    then the [ and ] are removed and one cannot save the view, BUT if one just writes a query using the same SQL string then it works correctly.

    I was also able to execute a SQL statement like:

    INSERT INTO [DevServerB\2K5].TestDB.dbo.tables ( ... ) ...
    

    I can do what I wanted, but it would have been much better if I could have saved a view and used a view that would then be used for SELECT, INSERT and UPDATE of the table in the [DevServerB\2K5].TestDB database from the original server where I tried and failed to create a view because of the '\' .

    -ASR-

提交回复
热议问题