Is there a system stored procedure to get the version #?
Is there a system stored procedure to get the version #?
Try
SELECT @@VERSION
or for SQL Server 2000 and above the following is easier to parse :)
SELECT SERVERPROPERTY('productversion')
, SERVERPROPERTY('productlevel')
, SERVERPROPERTY('edition')
Here's a bit of script I use for testing if a server is 2005 or later
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
Note : updated from original answer (see comment)
The KB article linked in Joe's post is great for determining which service packs have been installed for any version. Along those same lines, this KB article maps version numbers to specific hotfixes and cumulative updates, but it only applies to SQL05 SP2 and up.
If all you want is the major version for T-SQL reasons, the following gives you the year of the SQL Server version for 2000 or later.
SELECT left(ltrim(replace(@@Version,'Microsoft SQL Server','')),4)
This code gracefully handles the extra spaces and tabs for various versions of SQL Server.