8

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.

0

8 Answers 8

7
SELECT @@VERSION?

Or one of the SERVERPROPERTY options?

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

6

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

That's an ugly string to deal with programatically.
5

@@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

Good thinking about sp_dbcmptlevel. This matters more in some cases
1
SELECT SERVERPROPERTY('productversion')

The digits before the first period will give you the major version: 10 = 2008, 9 = 2005, 8 = 2000.

Comments

1

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

Comments

0

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.