Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine which version of SQL Server is running using T-SQL

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.

like image 868
Brono The Vibrator Avatar asked Feb 28 '11 19:02

Brono The Vibrator


3 Answers

SELECT @@VERSION?

Or one of the SERVERPROPERTY options?

like image 191
gbn Avatar answered Sep 20 '22 09:09

gbn


 SELECT SERVERPROPERTY('productversion')
       , SERVERPROPERTY ('productlevel')
       , SERVERPROPERTY ('edition')
like image 36
Pero P. Avatar answered Sep 24 '22 09:09

Pero P.


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')
like image 24
Oded Avatar answered Sep 24 '22 09:09

Oded