Get Sql Server major version number from serverproperty function

More for me than for you.  I’ve written and re-written this about 6 times this week and can’t seem to remember to save it off, so here I go.  This will return the major version number for the sql server being queried.  Sql Server 2000 = 8, Sql Server 2005 = 9, etc…

SELECT LEFT(CONVERT(SYSNAME,SERVERPROPERTY('ProductVersion')), CHARINDEX('.', CONVERT(SYSNAME,SERVERPROPERTY('ProductVersion')), 0)-1)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: