Brono The Vibrator
Brono The Vibrator

Reputation: 1155

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.

Upvotes: 8

Views: 10753

Answers (8)

Rakesh Reddy
Rakesh Reddy

Reputation: 1

EXEC[MASTER].SYS.[XP_MSVER]--To  get  the  server version

Upvotes: 0

SaDHacK
SaDHacK

Reputation: 89

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

Upvotes: 0

RichardTheKiwi
RichardTheKiwi

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

Oded
Oded

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

PedroC88
PedroC88

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

gbn
gbn

Reputation: 432631

SELECT @@VERSION?

Or one of the SERVERPROPERTY options?

Upvotes: 7

Joe Stefanelli
Joe Stefanelli

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

Pero P.
Pero P.

Reputation: 26992

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

Upvotes: 6

Related Questions