Reputation: 1155
I need help using T-SQL to figure-out the version of SQL Server running and execute different code sets based on weather SQL Server 2000 or Sql Server 2008 is running.
Upvotes: 8
Views: 10753
Reputation: 89
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
Upvotes: 0
Reputation: 107806
@@VERSION / SERVERPROPERTY
But you should also check
exec sp_dbcmptlevel 'dbname'
To ensure a certain feature works at the database's compatibility level.
Upvotes: 5
Reputation: 499302
Just query the database - there is a @@VERSION
property:
SELECT @@VERSION
Returns version, processor architecture, build date, and operating system for the current installation of SQL Server.
As mentioned on the page, since all of this data is returned in one varchar, you can use the SERVERPROPERTY function to retrieve only the version:
SELECT SERVERPROPERTY('ProductVersion')
Upvotes: 6
Reputation: 3839
Use to get the server SQL version:
SELECT SERVERPROPERTY('ProductVersion')
GO
Or for a more verbose command
SELECT @@VERSION
GO
Also in here you can find a list of the releases's version numbers
Upvotes: 1
Reputation: 135888
SELECT SERVERPROPERTY('productversion')
The digits before the first period will give you the major version: 10 = 2008, 9 = 2005, 8 = 2000.
Upvotes: 1
Reputation: 26992
SELECT SERVERPROPERTY('productversion')
, SERVERPROPERTY ('productlevel')
, SERVERPROPERTY ('edition')
Upvotes: 6