I want to use the procedure sp_spaceused on a table.
This procedures returns among others the size of the tables.
example:
sp_spaceused
database_name database_size unallocated space
db_test 216001.00 MB 196366.74 MB
After I perform a compression I want to recall the function in order to find the compression percentage.
I call again sp_spaceused.
How can I represent database_size internally in order to perform a division?
You can actually store the results of the stored procedure in a table. Once you have them in a table you can manipulate it however you need. To get stored procedure results into a table, you would first need to make a table with columns that match the resultset of the stored procedure. Then do an insert statement for the table but instead of a query or a value list, execute the stored procedure. Note, that this will only get the first resultset of a stored procedure into a table. For example, you could do:
After you execute the above statements the HoldSpaceUsed table will contain the stored procedure results. Remember that the database_size field has the ‘MB’ representing the database size is in megabyts, so you would need to trim out the ‘MB’ text so you have just the number and then you can use it however you need.