Why can't I use my server name (SQL Server)?

I'm about to study how to join tables from multiple, different databases. So the way I refer to a particular table is by following this format db_server_name.db_name.schema_name.table_name. So after searching around how to get the server name using this command :

SELECT @@SERVERNAME

I got the following server name:

LAPTOP-FV8FREL6\SQLEXPRESS

Also this confirms:

enter image description here

So I did this query :

select v.VendorID, v.VendorName
from LAPTOP-FV8FREL6\SQLEXPRESS.AP.dbo.Vendors v;

But it says

Msg 102, Level 15, State 1, Line 6 Incorrect syntax near '-'.

Do you know how to get this works?

Upvotes: 1

Views: 743

Answers (1)

alexherm
alexherm

Reputation: 1362

Put [ ] around your server name.

select v.VendorID, v.VendorName
from [LAPTOP-FV8FREL6\SQLEXPRESS].AP.dbo.Vendors v;

Upvotes: 5

Related Questions