Get Current SQL Server Details:
DECLARE @p_dateTime AS DATETIME;
DECLARE @p_SQL_Query NVARCHAR(100);
DECLARE @Table TABLE (AllData NVARCHAR(MAX));
DECLARE @p_ServerName NVARCHAR(50);
SET @p_SQL_Query = 'exec xp_cmdshell "net statistics server"';
SELECT @p_ServerName = CAST(SERVERPROPERTY('machinename') AS VARCHAR);
INSERT INTO @Table
EXEC (@p_SQL_Query);
SELECT @p_dateTime = SUBSTRING(AllData,17,LEN(AllData)) FROM @Table WHERE AllData LIKE 'Statistics since%';
SELECT 'The Server ['+@p_ServerName+'] is up from the date :'+ CAST(@p_dateTime AS VARCHAR)+' which is almost '+CAST(DATEDIFF(day,@p_dateTime,getdate()) AS VARCHAR) +' Days !!'
---------------------------------------------------------------------------------------------------------------
The Server [MAHALIRAJESH] is up from the date :Feb 22 2014 10:18AM which is almost 1 Days !!
(1 row(s) affected)