Sybase ASE: @@version, @@version_number, @@version_as_integer

For those of you that don’t know, way back in v12.5, Sybase added the static global variables @@version_number and @@version_as_integer. The purpose was to make it easier for programmers to write code that incorporate the new features of ASE 12.5 while still being able to support the older v12.0 servers.

How is this done? In ASE 12.0 and earlier, we were forced to determine the version of the Sybase ASE DBMS server by parsing the output of @@version. During the v11.5 through v12.0 years, the format of the @@version static variable changed. The location of certain fields within the string kept being moved around. IIRC, it was about the time that v12.0.0.2 came out that the format was set in stone.

OLD way of determining the version of the ASE server for use in your application:

   my $version_str = dbS::Sybase::Queries::selectrow_array($dbh, 'select @@version');
    my @version = split ///, $version_str;
    print "ASE version: $version[1]\\n";


ASE version:  15.0.2

In this case, we are assuming that the second field in @@version is the part that contains “15.0.2” but there is absolutely no guarantee. Granted, we could be a bit more proactive with our parsing and determine that a field with one or more digits followed by a period and more digits (there can be more than one of these sets of \\d+\\.\\d+). It can be confusing for those people not used to using regular expressions (regex’s). Why complicate things just for a version string?

New-ish way:

my $version = dbS::Sybase::Queries::selectrow_array($dbh, 'select @@version_number');
    print "ASE version: $version\\n";


ASE version:  15020

Here we ask for the version as a number, and we receive it. It is easier to work with the number ‘15020’ than the string ‘15.0.2’ to determine if a code chunk requires a minimum of (12504).

What if you’re only looking for the major version number? Basically, if the ASE version is 11x, 12x, or 15x. Easily done:

my $version = dbS::Sybase::Queries::selectrow_array($dbh, 'select @@version_as_integer');
    print "ASE version: $version\\n";


ASE version:  15000

That’s it 🙂

Share Button

3 Replies to “Sybase ASE: @@version, @@version_number, @@version_as_integer”

  1. Where does the 64 bit come from in the @@version command? Is it getting it from the operating system or the Sybase software?Adaptive Server Enterprise/12.5.3/EBF 12146/P/RS6000/AIX 5.1/ase125x/1883/64-bit/FBO/Thu Nov 11 22:31:37 2004

  2. select @@version_as_integer does not work on versions older than 12.5

    Adaptive Server Enterprise/ 11690 ESD1/Sun_svr4/OS 5.7/2047/64bit/FBO/Fri Feb 13 05:48:35 2004

    Must declare variable ‘@@version_as_integer’.

Leave a Reply

Your email address will not be published. Required fields are marked *