Problems with hyphen in computer (server) name

  • I have found that I get an SQL syntax error when using a hyphenated server name in a query. Example:

    Select * from my-server.mydb.owner.table

    This is allowed in the Microsoft computer naming rules but SQL doesn't like it. This would affect any distributed query. I am posting this because I haven't been able to find a lot of info on this.

  • Select * from [my-server].mydb.owner.table

  • As Allen stated you need to use the square brackets and you should be OK. The only place I have found where this doesn't work is when you are using osql and bcp from the command line. One work around is to use a different server name on your linked server (IE: change the linked server to use an _ instead). The only way you can do that though is to use OLEDB instead of the native SQL provider.

    Gary Johnson

    Microsoft Natural Language Group

    DBA, Sr. DB Engineer




    Gary Johnson
    Microsoft Natural Language Group
    DBA, Sr. DB Engineer

    This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.

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

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