크기에 따라 mb 로 변환하기에 소수점이 나올 경우 kb 로 반환하고, 그 보다 크면 mb 로 변환처리 했습니다.
SELECT NAME, FILENAME, FileLength AS BYTES, (CASE WHEN FileLength < 1000000 THEN CONCAT(CEILING(FileLength / 1024.0), ' KB') ELSE CONCAT(FORMAT(FileLength / 1048576.0, 'N3'), ' MB') END) AS KB_MB, WriteDate FROM [dbo].[UNIV_COM_AttachUser] WHERE WriteDate BETWEEN '2022-10-21 11:44' AND '2022-10-21 11:59' ORDER BY WriteDate ASC
https://stackoverflow.com/a/42126331
Converting bytes to kilobytes/megabytes
I have an attachments table that stores the size of the document in Bytes. I'm needing to display a result set of all documents in either KB or MB. In KB if the document is less than 1MB or in MB ...
stackoverflow.com
* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.