Fully Qualified table name syntax

I would like to write a query accessing two tables using ADO in VB6. The syntax for fully qualified tables names is [server].[databasename].[owner].[table name].

When the server name is SQL2000, the fully qualified name works( Select * from SQL2000.jir.dbo.CusFil ). However, when the server name is fs-jirsql, I receive an error becasue of the hyphen( Select * from fs-jirsq1.jir.dbo.CusFil ). Alternately, I tried the IP address, but the periods in the IP confuse SQL( Select * from ).
How do I correctly format the fully qualified table name in a select statement when either the server name contains a hyphen or when I only have the IP address and not the server name?

Who is Participating?
That server name is a 'logical' name

That is to say that the server name must match a linked server.

If you want to use the servers physical IP address in your query, there are two options:

1. Create a linked server whose logical name matches the IP address. Basically this is an option but I can't see any practical reason for doing it. If your physical server changes IP addresses, your linked server name will not change.


   'SELECT * FROM jir.dbo.CusFil') AS a

But there is rarely a good reason to refer to server IP addresses - thats what DNS is for!!

Select * from [fs-jirsq1].jir.dbo.CusFil
SQL Server has a long history of not liking the hypen in a name.
you could also have spaces  in a name   the best way is to not use them in names but
to always code within enclosed square brackets

[server].[databasename].[owner].[table name]

the square brackets are there for a purpose (in your example)...


mpdillonAuthor Commented:
Thanks very much. The square brackets work great with a name that contains a hyphen. However, I tried the IP address in the square brackets and it did not work. I received a message saying to add the server using sp_addlinkedserver. I read a little about this stored procedure but I don't think it is what I want. Is there a way to use the IP address in a fully qualified name?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.