I'm using the function sp_spaceused to get the details of all the tables in a DB. The index_size column is VARCHAR returned complete with ' KB' on the end, however I want to to display in MB. All I need to know is how to strip out the KB, I can do the rest! :D
UPDATE: I don't feel this is a duplicate of the other question suggested as I was looking for a SQL only solution, which was given in this thread.
My first thought would be to just store in in a variable and just use substring to remove the last characters.
REPLACE(column, 'KB', ''). No need for LEN and other stuff
On SQL 2005, this will give you the "reserved" value:
Some more investigation should allow you to read index vs data space out of the catlog views too
More generic solution:
General solution for T-SQL (SS 2008+), to remove all but a set of allowed characters:
This could easily be encapsulated into a scalar function. A completely general function would accept the list of characters allowed, or you could hard-code for special purpose (like this one).