HOWTO: Obtain Microsoft SQL Server Version Information

ID: Q191867


The information in this article applies to:
  • Microsoft Visual FoxPro for Macintosh, version 3.0b
  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0, 5.0a, 6.0


SUMMARY

Information regarding the versions of Microsoft SQL Server can be useful when you are writing commands that are intended to be specific to a particular version of SQL Server.

There are four possible ways to check for version information as follows:

  • Use the "@@version" global variable.

    -or-


  • Use the "xp_msver" extended stored procedure.

    -or-


  • Use the xp_regread extended stored procedure to examine the registry.

    -or-


  • Query the version column of the sysdatabases table.


All four of these methods return the same information. This article shows how to obtain the SQL Server version information from within Visual FoxPro.


MORE INFORMATION

Example One

The first example illustrates the use of SQL Server's @@version global variable to obtain SQL Server versioning information.

  1. Create a program file called Sqlvers1.prg containing the following code:
    
          connection_string='DRIVER={SQL Server};SERVER=MYSERVER;' + ;
             'DATABASE=PUBS;UID=sa;PWD='
          gnConnHandle=SQLSTRINGCONN(connection_string)
          IF gnConnHandle>0
             TEST=SQLEXEC(gnConnHandle,'select @@version','getversion')
             SELECT getversion
             versioninfo=EXP
             sqldisconn(gnConnHandle)
             =MESSAGEBOX(versioninfo,48,"SQL Server Version")
          ELSE
             =MESSAGEBOX("Connection Failed",16,"ODBC Problem")
          ENDIF 


  2. From the Command window type the following:
    
          DO SQLVERS1 


Example Two

The second example illustrates the use of SQL Server's xp_msver extended stored procedure to obtain SQL Server versioning information.

  1. Create a program file called Sqlvers2.prg containing the following code:
    
          connection_string='DRIVER={SQL Server};SERVER=MYSERVER;' + ;
             'DATABASE=PUBS;UID=sa;PWD='
          gnConnHandle=SQLSTRINGCONN(connection_string)
          IF gnConnHandle>0
             TEST=SQLEXEC(gnConnHandle,'exec xp_msver','getversion')
             SELECT getversion
             versioninfo=EXP
             sqldisconn(gnConnHandle)
             =MESSAGEBOX(versioninfo,48,"SQL Server Version")
          ELSE
             =MESSAGEBOX("Connection Failed",16,"ODBC Problem")
          ENDIF 


  2. From the Command window type following and then compare the output with the information obtained using the @@version global variable:
    
           DO SQLVERS2 


Example Three

The third example illustrates the use of SQL Server's xp_regread extended stored procedure to obtain SQL Server versioning information.

  1. Create a program file called Sqlvers3.prg containing the following code:
    
          connection_string='DRIVER={SQL Server};SERVER=MYSERVER;' + ;
             'DATABASE=PUBS;UID=sa;PWD='
          gnConnHandle=SQLSTRINGCONN(connection_string)
          IF gnConnHandle>0
             TEST=SQLEXEC(gnConnHandle,'exec xp_regread','getversion')
             SELECT getversion
             versioninfo=EXP
             sqldisconn(gnConnHandle)
             =MESSAGEBOX(versioninfo,48,"SQL Server Version")
          ELSE
             =MESSAGEBOX("Connection Failed",16,"ODBC Problem")
          ENDIF 


  2. From the Command window type the following and then compare the output with the information obtained using the @@version global variable and the xp_msver extended stored procedure:
    
          DO SQLVERS3 


Example Four

The fourth example illustrates the use of information contained in the version column of the sysdatabases table to obtain SQL Server version information.

  1. Create a program file called Sqlvers4.prg containing the following code:
    
          connection_string='DRIVER={SQL Server};SERVER=MYSERVER;' + ;
             'DATABASE=PUBS;UID=sa;PWD='
          gnConnHandle=SQLSTRINGCONN(connection_string)
          IF gnConnHandle>0
             sqlcommand="SELECT version FROM sysdatabases WHERE dbid = 1"
             TEST=SQLEXEC(gnConnHandle,sqlcommand,'getversion')
             SELECT getversion
             versioninfo=EXP
             sqldisconn(gnConnHandle)
             =MESSAGEBOX(versioninfo,48,"SQL Server Version")
          ELSE
             =MESSAGEBOX("Connection Failed",16,"ODBC Problem")
          ENDIF 


  2. From the Command window type the following and then compare the output with the information obtained using the @@version global variable and the extended stored procedures:
    
          DO SQLVERS4 


(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by John Desch, Microsoft Corporation.

Additional query words: kbSQL kbSQLServ kbVFp600 kbVFp300b kbVFp300 kbVFp500a kbVFp500 kbMAC

Keywords :
Version : MACINTOSH:3.0b; WINDOWS:3.0,3.0b,5.0,5.0a,6.0
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


Last Reviewed: August 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.