Straff
Straff

Reputation: 43

Convert column in SQL database from KB to MB

Asked around but no answers, hence the question here.

I've a SQL table with Column 'Length'.

This is file sizes expressed as KB. I'm trying to convert the entire column to MB and then produce a report of those that are between particular sizes.

Apologies for being dumb, but I just can't find an answer anywhere.

Upvotes: 1

Views: 17661

Answers (1)

Barranka
Barranka

Reputation: 21047

Divide the value by 1024:

select a.*, length / 1024 as length_mb
from yourTable as a
where (length / 1024) between value1 and value2

You can, of course, round the value using round() if you need to.


Rounding values:

select a.*, round(length / 1024, 2) as length_mb
from yourTable as a
where round(length / 1024, 2) between value1 and value2

Upvotes: 3

Related Questions