views:

2538

answers:

7

Is there a system stored procedure to get the version #?

+2  A: 

SELECT @@VERSION

Brannon
+11  A: 

Try

SELECT @@VERSION

or for SQL Server 2000 and above the following is easier to parse :)

SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'), SERVERPROPERTY('edition')

From: http://support.microsoft.com/kb/321185

Joe Kuemerle
A: 

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.

Matt
+1  A: 

Here's a bit of script I use for testing if a server is 2005 or later

declare @isSqlServer2005 bit
select @isSqlServer2005 = case when SERVERPROPERTY('productversion') < '9.00.0000.00' then 0 else 1 end
select @isSqlServer2005
Bruce Chapman
A: 

This doesn't work for me on SQL2008, product version is 10.0.2531.0, the comparison doesn't work

Rick Hallock
A: 

try this: if (SELECT LEFT(CAST(SERVERPROPERTY('productversion') as varchar), 2)) = '10' BEGIN

freak