Gets a property value of an OLE object.
sp_OAGetProperty objecttoken,
propertyname
[, propertyvalue OUTPUT]
[, index...]
If the property returns an OLE object, propertyvalue must be a local variable of data type int. An object token is stored in the local variable, and this object token can be used with other OLE Automation stored procedures.
If the property returns a single value, either specify a local variable for propertyvalue, which returns the property value in the local variable, or do not specify propertyvalue, which returns the property value to the client as a single-column, single-row result set.
When the property returns an array, if propertyvalue is specified, it is set to NULL.
If propertyvalue is specified, but the property does not return a value, an error occurs. If the property returns an array with more than two dimensions, an error occurs.
Some properties have parameters. These properties are called indexed properties, and the parameters are called index parameters. A property can have multiple index parameters.
Note The parameters for this stored procedure are specified by position, not name.
0 (success) or a nonzero number (failure) that is the integer value of the HRESULT returned by the OLE Automation object.
For more information about HRESULT Return Codes, see OLE Automation Return Codes and Error Information.
If the property returns an array with one or two dimensions, the array is returned to the client as a result set:
When a property return value or method return value is an array, sp_OAGetProperty or sp_OAMethod returns a result set to the client. (Method output parameters cannot be arrays.) These procedures scan all the data values in the array to determine the appropriate Microsoft® SQL Server™ data types and data lengths to use for each column in the result set. For a particular column, these procedures use the data type and length required to represent all data values in that column.
When all data values in a column share the same data type, that data type is used for the whole column. When data values in a column use different data types, the data type of the whole column is chosen based on the following chart.
int | float | money | datetime | varchar | |
---|---|---|---|---|---|
int | int | float | money | varchar | varchar |
float | float | float | money | varchar | varchar |
money | money | money | money | varchar | varchar |
datetime | varchar | varchar | varchar | datetime | varchar |
varchar | varchar | varchar | varchar | varchar | varchar |
You can also use sp_OAMethod to get a property value.
This example gets the HostName property (of the previously created SQLServer object) and stores it in a local variable.
DECLARE @property varchar(255)
EXEC @hr = sp_OAGetProperty @object, 'HostName', @property OUT
IF @hr <> 0
BEGIN
EXEC sp_displayoaerrorinfo @object, @hr
RETURN
END
PRINT @property
This example gets the HostName property (of the previously created SQLServer object) and returns it to the client as a result set.
EXEC @hr = sp_OAGetProperty @object, 'HostName'
IF @hr <> 0
BEGIN
EXEC sp_displayoaerrorinfo @object, @hr
RETURN
END