tags:

views:

313

answers:

2

Does anyone know how to get the operating system information from a microsoft sql server instance via sql?

Using SERVERPROPERTY can get some information but I need to get the operating system e.g. 'Microsoft Windows NT 5.2 (3790)'

Thanks

+1  A: 

I've used something like this before:

exec master..xp_cmdshell 'systeminfo'

Lloyd
You'd hope xp_cmdshell is disabled on a production server.
Andomar
Yes definitely I just recall doing it once.
Lloyd
+2  A: 

Extract from @@VERSION

Eg:

PRINT @@VERSION

Another way is to build a CLR Function or Stored Procedure. Here is a sample code:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString Function1()
    {
        return new SqlString(System.Environment.OSVersion.ToString());
    }
};

This example should output this:

SELECT dbo.Function1()

Microsoft Windows NT 6.0.6001 Service Pack 1
NinethSense