Get @@SERVERNAME from linked server This seems like a basic question but I can't find any answers out there - I need to be able to get the server name/instance etc. from a linked server. I've tried a couple of things:

select &lt;linked server&gt;.@@SERVERNAME;
select &lt;linked server&gt;.SERVERPROPERTY('ServerName');


... but no joy. Any ideas?

This is SQL 2008 R2 &amp; 2014 (2008R2 is the linked server)

EDIT: Errors are:


  Msg 102, Level 15, State 1, Line 2 Incorrect syntax near
  '@@SERVERNAME'.
Some slightly shorter (and more natural, IMHO) approaches:

EXEC LinkedServer.[master].sys.sp_executesql N'SELECT @@VERSION;';


Or:

EXEC('SELECT @@VERSION;') AT LinkedServer;


I prefer the sp_executesql route because:


It will still allow for strongly-typed parameters, instead of dealing with all kinds of string concatenation, escaping of single quotes, etc.
It is easy to specify a particular database in that path, instead of having to put database prefixes on all the objects referenced in the query. And yes, you can define the database dynamically:

DECLARE @db SYSNAME, @exec NVARCHAR(1024);
SET @db = N'tempdb';
SET @exec = N'LinkedServer.' + QUOTENAME(@db) + N'.sys.sp_executesql';
EXEC @exec N'SELECT @@VERSION, DB_NAME();';


And the linked server name, too, if need be:

DECLARE @srv SYSNAME, @db SYSNAME, @exec NVARCHAR(1024);
SET @srv = N'LinkedServer';
SET @db = N'tempdb';
SET @exec = QUOTENAME(@srv) + N'.' + QUOTENAME(@db) + N'.sys.sp_executesql';
EXEC @exec N'SELECT @@VERSION, DB_NAME();';