Size of VARBINARY field in SQL Server 2005

Tewr picture Tewr · Feb 3, 2009 · Viewed 52.1k times · Source

I am trying to determine the size in bytes of the contents in a VARBINARY(MAX) field in SQL Server 2005, using SQL. As I doubt there is native support for this, could it be done using CLR integration? Any ideas would be greatly appreciated.

Answer

mwigdahl picture mwigdahl · Feb 3, 2009

Actually, you can do this in T-SQL!

DATALENGTH(<fieldname>) will work on varbinary(max) fields.