The following query is used to get the SQL Server Uptime. Implicitly defines the SQL Server Services uptime.
USE [master]
GO
/****** Object: StoredProcedure [dbo].[GetSQLUptime]******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetSQLUptime]
AS
BEGIN
Declare @theMinutes int
Set @theMinutes = (SELECT TOP 1 DATEDIFF(mi,login_time, GETDATE()) AS TotalUpTimeInMinutes FROM sys.sysprocesses ORDER BY login_time)
Select @@SERVERNAME AS ServerName, convert(varchar(15), @theMinutes / 1440 ) + ' Days, ' + REPLICATE('0', 2 - DATALENGTH(convert(varchar(2), (@theMinutes % 1440) / 60 ))) + convert(varchar(2), (@theMinutes % 1440) / 60 ) + ' Hours, ' + REPLICATE('0', 2 - DATALENGTH(convert(varchar(2), (@theMinutes % 60)))) + convert(varchar(2), (@theMinutes % 60)) + ' Minutes' AS SQLUptime_Days_Hours_Minutes
END
GO
USE [master]
GO
/****** Object: StoredProcedure [dbo].[GetSQLUptime]******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[GetSQLUptime]
AS
BEGIN
Declare @theMinutes int
Set @theMinutes = (SELECT TOP 1 DATEDIFF(mi,login_time, GETDATE()) AS TotalUpTimeInMinutes FROM sys.sysprocesses ORDER BY login_time)
Select @@SERVERNAME AS ServerName, convert(varchar(15), @theMinutes / 1440 ) + ' Days, ' + REPLICATE('0', 2 - DATALENGTH(convert(varchar(2), (@theMinutes % 1440) / 60 ))) + convert(varchar(2), (@theMinutes % 1440) / 60 ) + ' Hours, ' + REPLICATE('0', 2 - DATALENGTH(convert(varchar(2), (@theMinutes % 60)))) + convert(varchar(2), (@theMinutes % 60)) + ' Minutes' AS SQLUptime_Days_Hours_Minutes
END
GO
Comments
Post a Comment