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.
8 Answers
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')
1 Comment
@@VERSION / SERVERPROPERTY
But you should also check
exec sp_dbcmptlevel 'dbname'
To ensure a certain feature works at the database's compatibility level.
1 Comment
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