Tuesday, March 27, 2012

Basic formatting questions

I have two questions concerning formatting output in SQL.

I have a processer speed column that I would like to make usable. A sample entry is 2793, which I would like to be returned as '2.8 GHz'. I am using the following successfully, but when I try to append the ' GHz' it gives me a conversion error (I have tried putting both a cast and convert around the round statement).
ROUND(CONVERT(DECIMAL,PCCPUSpeed_IN) / 1000,1) + ' GHz'

Secondly, I have a RAM colum that stores values such as 534753280. I would like the results to fallin into 64 Mb buckets. So values between 512000 & 532480 should return '512 Mb'. I realize I can do this using a CASE statement, but is there a better way?

Thanks,

RobAll formatting really ought to be done on the client or at least in the middle tier. Doing formatting in the database is suicidal from both a performance and a scaling perspective in the long term.

-PatP

No comments:

Post a Comment