What is the size of a image field content in SQL Server?

Go To StackoverFlow.com

39

I have a table in SQL Server. This table has an image field and the application stores files in it.

Is there a way to read the size of the file in the image field using T-SQL?

2012-04-04 21:21
by Fabio


71

SELECT DATALENGTH(imagecol) FROM  table

See MSDN

2012-04-04 21:26
by Phil
The result will be the number of bytes - slartidan 2016-02-12 10:40
In megabytes it would be SELECT DATALENGTH(imagecol) / 1048576.0 FROM tableAleksei Mialkin 2016-03-04 17:04


4

Different display styles:

SELECT DATALENGTH(imagecol) as imgBytes,
       DATALENGTH(imagecol) / 1024 as imgKbRounded,
       DATALENGTH(imagecol) / 1024.0 as imgKb,      
       DATALENGTH(imagecol) / 1024 / 1024 as imgMbRounded,
       DATALENGTH(imagecol) / 1024.0 / 1024.0 as imgMb
FROM   table

Example output:

imgBytes    imgKbRounded    imgKb       imgMbRounded    imgMb
68514       66              66.908203   0               0.065340041992
2017-06-20 10:03
by j03p
Ads