declare @isSqlServer2005 bit
select @isSqlServer2005 = case when CONVERT(int, SUBSTRING(CONVERT(varchar(15), SERVERPROPERTY('productversion')), 0, CHARINDEX('.', CONVERT(varchar(15), SERVERPROPERTY('productversion'))))) < 9 then 0 else 1 end
select @isSqlServer2005
SELECT
@@SERVERNAME AS ServerName,
CASE WHEN LEFT(CAST(serverproperty('productversion') as char), 1) = 9 THEN '2005'
WHEN LEFT(CAST(serverproperty('productversion') as char), 2) = 10 THEN '2008'
WHEN LEFT(CAST(serverproperty('productversion') as char), 2) = 11 THEN '2012'
END AS MajorVersion,
SERVERPROPERTY ('productlevel') AS MinorVersion,
SERVERPROPERTY('productversion') AS FullVersion,
SERVERPROPERTY ('edition') AS Edition
CREATE FUNCTION dbo.UFN_GET_SQL_SEVER_VERSION
(
)
RETURNS sysname
AS
BEGIN
DECLARE @ServerVersion sysname, @ProductVersion sysname, @ProductLevel sysname, @Edition sysname;
SELECT @ProductVersion = CONVERT(sysname, SERVERPROPERTY('ProductVersion')),
@ProductLevel = CONVERT(sysname, SERVERPROPERTY('ProductLevel')),
@Edition = CONVERT(sysname, SERVERPROPERTY ('Edition'));
--see: http://support2.microsoft.com/kb/321185
SELECT @ServerVersion =
CASE
WHEN @ProductVersion LIKE '8.00.%' THEN 'Microsoft SQL Server 2000'
WHEN @ProductVersion LIKE '9.00.%' THEN 'Microsoft SQL Server 2005'
WHEN @ProductVersion LIKE '10.00.%' THEN 'Microsoft SQL Server 2008'
WHEN @ProductVersion LIKE '10.50.%' THEN 'Microsoft SQL Server 2008 R2'
WHEN @ProductVersion LIKE '11.0%' THEN 'Microsoft SQL Server 2012'
WHEN @ProductVersion LIKE '12.0%' THEN 'Microsoft SQL Server 2014'
END
RETURN @ServerVersion + N' ('+@ProductLevel + N'), ' + @Edition + ' - ' + @ProductVersion;
END
GO