Saturday, November 24, 2012

SQL Server Uptime

SET NOCOUNT ON
DECLARE @db_cr_date DATETIME,
@hour int,
@minute int,
@days int

SELECT @db_cr_date=crdate FROM
master.sys.sysdatabases
WHERE NAME='inertiamusic'

SET @minute = DATEDIFF (mi,@db_cr_date,GETDATE())
SET @days= @minute/1440
SET @hour = (@minute/60) - (@days * 24)
SET @minute= @minute - ( (@hour + (@days*24)) * 60)

Select @@SERVERNAME
+' is restarted on '
+ CAST(@db_cr_date as varchar(30))
+ ' Server is up and running since last : '
+ ltrim(str(@days)) +' Days,'
+ ltrim(str(@hour)) +' Hours, '
+ ltrim(str(@minute)) + ' Minutes ' as [Total Uptime]

No comments:

Post a Comment