Byte Conversion
We created a parameterized snippet to take a raw amount of bytes and convert it to Kilobytes, Megabytes, Gigabytes, and Terabytes accordingly.
Snippet Name: Byte_Conversion(byte_field)
Snippet Text:
case when [byte_field] > 1099511627776 then round(1.0 *[byte_field] / 1099511627776, 2 )::decimal(6, 2) || ' TB' when [byte_field] > 1073741824 then round(1.0 *[byte_field] / 1073741824, 2 )::decimal(6, 2) || ' GB' when [byte_field] > 1048576 then round(1.0 *[byte_field] / 1048576, 2 )::decimal(6, 2) || ' MB' when [byte_field] > 1024 then round(1.0 *[byte_field] / 1024, 2 )::decimal(6, 2) || ' KB' else [byte_field] || ' B' end
Can be used in a chart like this, where the table column is num_bytes:
Select
[byte_conversion(num_bytes)] as num_bytes
Please sign in to leave a comment.
Comments
0 comments