I need help using T-SQL to determine the SQL Server startup version and the execution of various sets of code based on SQL Server 2000 or Sql Server 2008 weather.
SELECT @@VERSION?
Or one of the SERVERPROPERTY parameters?
SELECT SERVERPROPERTY('productversion') , SERVERPROPERTY ('productlevel') , SERVERPROPERTY ('edition')
@@ VERSION / SERVERPROPERTY
But you should also check
exec sp_dbcmptlevel 'dbname'
To ensure that a particular function works at the database compatibility level.
Just query the database - there is a @@VERSION property:
@@VERSION
SELECT @@VERSION
Returns the version, processor architecture, build date, and operating system for the current installation of SQL Server.
As mentioned on the page, since all this data is returned in one varchar, you can use the SERVERPROPERTY function to retrieve only the version
SELECT SERVERPROPERTY('ProductVersion')
SELECT SERVERPROPERTY('productversion')
The numbers before the first period will give you the basic version: 10 = 2008, 9 = 2005, 8 = 2000.
Use to get the SQL version of the server:
SELECT SERVERPROPERTY('ProductVersion') GO
Or for a more detailed command
SELECT @@VERSION GO
Also in here you can find a list of version numbers of versions
SELECT SERVERPROPERTY ('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')
EXEC[MASTER].SYS.[XP_MSVER]--To get the server version