sql-serverclrgeographyversion-detection

How to determine SQL Server 2008 or above


I need to determine programmatically if the database supports the Geography data type and Spatial indexes. These features were introduced in 2008. I also need to determine if CLR is enabled as these features rely on it. What is the most reliable way to do this?


Solution

  • SQL Server 2008 is 10.x

    You can use SERVERPROPERTY in SQL and query sys.configurations

    SELECT
       PARSENAME(CAST(SERVERPROPERTY('ProductVersion') AS varchar(20)), 3) AS MajorVersion, 
       value_in_use
    FROM 
       sys.configurations
    WHERE
       name = 'clr enabled';
    

    Edit: added CAST