Link to home
Start Free TrialLog in
Avatar of mpdillon
mpdillon

asked on

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, 10.0.0.120 but the periods in the IP confuse SQL( Select * from 10.0.0.120.jir.dbo.CusFil ).
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?

thanks,
SOLUTION
Avatar of ptjcb
ptjcb
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SQL Server has a long history of not liking the hypen in a name.
SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mpdillon
mpdillon

ASKER

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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial