59

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?

shA.t
  • 16,580
  • 5
  • 54
  • 111
Fabio
  • 1,037
  • 1
  • 10
  • 22

2 Answers2

104
SELECT DATALENGTH(imagecol) FROM  table

See MSDN

Phil
  • 42,255
  • 9
  • 100
  • 100
13

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
j03p
  • 321
  • 3
  • 11