For SQL Server start time, I use this:select SQL_Server_Start_Time = min(login_time) from sysprocessesSQL_Server_Start_Time ------------------------------------------------------ 2006-04-07 17:03:23.493(1 row(s) affected)
For system uptime, I usually get it with the PSINFO utility:C:\>PSINFO \\MYCOMPUTERPsInfo v1.73 - Local and remote system information viewerCopyright (C) 2001-2005 Mark RussinovichSysinternals - www.sysinternals.comSystem information for \\MYCOMPUTER:Uptime: 0 days 2 hours 50 minutes 58 secondsKernel version: Microsoft Windows 2000, Uniprocessor FreeProduct type: ProfessionalProduct version: 5.0Service pack: 4Kernel build number: 2195Registered organization:Registered owner: Dr. EvilInstall date: 3/18/2002, 5:48:16 PMActivation status: Not applicableIE version: 6.0000System root: C:\WINNTProcessors: 1Processor speed: 930 MHzProcessor type: Intel Pentium IIIPhysical memory: 256 MBVideo driver: Radeon DDRC:\>
You can also get the system start time from the system event log with the PSLOGLIST utility by looking to see when the event log was last started:C:\>psloglist -id 6005 -n 1PsLoglist v2.62 - local and remote event log viewerCopyright (C) 2000-2005 Mark RussinovichSysinternals - www.sysinternals.comSystem log on \\MYCOMPUTER:[5986] EventLog Type: INFORMATION Computer: MYCOMPUTER Time: 4/7/2006 5:03:10 PM ID: 6005The Event log service was started.
Combining the two sources of info:set nocount ondrop table #tcreate table #t (cmdout varchar(500) )insert into #texec master.dbo.xp_cmdshell 'psloglist -id 6005 -n 1'select SYSTEM_UP_SINCE = convert(datetime,substring(cmdout,14,22)), SQL_SERVER_START_TIMEfrom #t cross join (select SQL_SERVER_START_TIME = min(login_time) from sysprocesses ) awhere cmdout like '% Time: %' Results:SYSTEM_UP_SINCE SQL_SERVER_START_TIME----------------------- -----------------------2006-04-07 17:03:10.000 2006-04-07 17:03:23.493
CODO ERGO SUM