SQL Server Performance

@@version year

Discussion in 'General Developer Questions' started by i.netdeveloper, Jul 15, 2010.

  1. Hi, I want to a script based on sql server version year, because some objects are not supported in 2000. We have two enviorments.
    something like
    if @@version = 'Microsoft Sqlserver 2000'
    --do this
    if @@version ='Microsoft Sqlserver 2008'
    -- do this
    I really appreciate your help.
    Thanks...
  2. Adriaan New Member

    I would maintain separate scripts. This way you stay out of trouble, rather than inviting it in.
    For instance, what about SQL 2005?
  3. Adriaan New Member

    On the syntax side, just remember that you can use LIKE and wildcards in any string comparison, so you could simply do:
    IF @@VERSION LIKE 'Microsoft SQL Server 2000%'
    Another option would be to extract the year from the whole string:
    SELECT SUBSTRING(@@VERSION, 22, 4)
    ... but of course Microsoft might surprise us in a future version with a different layout for the results from @@VERSION.
  4. satya Moderator

    Rather than @@version you can take help of SERVERPROPERTY('productversion') where the first 4 digits indicates version 8 is 2000, 9 is 2005 and so on.
  5. Madhivanan Moderator

    [quote user="satya"]
    Rather than @@version you can take help of SERVERPROPERTY('productversion') where the first 4 digits indicates version 8 is 2000, 9 is 2005 and so on.
    [/quote]
    orif (select parsename(cast(SERVERPROPERTY('productversion') as varchar(100)),4))=8
    -- Do stuff for version 2000 if (select parsename(cast(SERVERPROPERTY('productversion') as varchar(100)),4))=9
    -- Do stuff for version 2005
    if (select parsename(cast(SERVERPROPERTY('productversion') as varchar(100)),4))=10
    -- Do stuff for version 2008

Share This Page