Using diskfree to Retrieve a Data Value from the External Environment

The PROCSRV procedure diskfree is an example of the use of output parameters in an Open Data Services stored procedure. The diskfree procedure returns the number of bytes of free space for the drive letter passed to it as a parameter. To use diskfree, you must declare and initialize a variable to hold the return parameter and use the OUTPUT keyword when calling the procedure, as follows:

declare @outvar int
execute PROCSRV...diskfree @drive = 'c', @space = @outvar OUTPUT
select @outvar
  

Return parameters in PROCSRV are treated in the same way as standard SQL Server stored procedure parameters. For example, when the EXECUTE statement completes, the @outvar variable contains the return value from the PROCSRV procedure. If the three lines in this example were part of a stored procedure in SQL Server itself, the return value of @outvar could then be used in subsequent statements.

The diskfree procedure also accepts a default parameter. If you execute diskfree without specifying a drive-letter parameter, diskfree returns a data row showing free space for the drive on which PROCSRV is installed.

For more information about using return parameters in stored procedures, see the Microsoft SQL Server Transact-SQL Reference.