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

Sql ServerTsqlDatalength

Sql Server Problem Overview


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?

Sql Server Solutions


Solution 1 - Sql Server

SELECT DATALENGTH(imagecol) FROM  table

See MSDN

Solution 2 - Sql Server

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFabioView Question on Stackoverflow
Solution 1 - Sql ServerPhilView Answer on Stackoverflow
Solution 2 - Sql Serverj03pView Answer on Stackoverflow