Can't run query using "localhost\sqlexpress" I am trying dynamically build an SQL Statement that includes linked server. That works. When I use "localhost" to reference the current local machine SQL Server, that doesn't work.

For example:

Select * From [LOCALHOST\SQLEXPRESS].[My_Database].[dbo].[My_Table]


However, if I specify my machine name instead, it will work.

Select * From [My_Machine\SQLEXPRESS].[My_Database].[dbo].[My_Table]


Why can't I reference Localhost?
You can only reference servers that are listed under Server Objects -> Linked Servers as well as the local server via what you get back from @@SERVERNAME. Four part naming does not trigger a NETBIOS / DNS lookup. If you are referencing the local machine anyway, why not just use three part naming?