Easy SQL Server Version Identification

  • I know about @@version and SERVERPROPERTY, but I am looking for a query that will determine between SQL Server 2000 and 2005. I need to write an if/then statement and don't want to have to add all of the 9.xxx.xx versions for 2005 and keep that updated with each hotfix that comes out.

    -Kyle

  • Kyle,

    I usually use

    IF CONVERT(char(1),SERVERPROPERTY('ProductVersion'))<'9'  --pre SQL 2005

    BEGIN...

    Or something along these lines when I need to make code compatible for 2005 and older versions. Probably there are better ways but so far it worked fine for me.

    Markus

    [font="Verdana"]Markus Bohse[/font]

  • declare

    @SQLV char(1)

    select

    @sqlv = convert(char(1),serverproperty('productversion'))

    select

    @sqlv

  • This was the answer.  Thanks to all who helped.  The final query looked like this...

    IF CONVERT(char(1),SERVERPROPERTY('ProductVersion'))>'9'  --pre SQL 2005

    BEGIN

    select name, is_policy_checked

    from sys.sql_logins

    END

    Kyle,

    I usually use

    IF CONVERT(char(1),SERVERPROPERTY('ProductVersion'))<'9'  --pre SQL 2005

    BEGIN...

    Or something along these lines when I need to make code compatible for 2005 and older versions. Probably there are better ways but so far it worked fine for me.

    Markus

  • THANKS! I needed that too. I love SQLServerCentral.com.

    mmmuah!

    😎

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply