Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of VARBINARY field in SQL Server 2005

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.

like image 631
Tewr Avatar asked Feb 03 '09 16:02

Tewr


People also ask

What is the size of VARBINARY?

varbinary [ ( n | max) ] Variable-length binary data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes.

How do I find the size of a field in SQL?

In our case DATALENGTH T-SQL function came real handy to know the actual size of the data in this column. According to books online, DATALENGTH (expression) returns the length of the expression in bytes (or) the number of bytes SQL needed to store the expression which can be of any data type.

What is VARBINARY data type in SQL Server?

Description. The VARBINARY type is similar to the VARCHAR type, but stores binary byte strings rather than non-binary character strings. M represents the maximum column length in bytes. It contains no character set, and comparison and sorting are based on the numeric value of the bytes.

How can I see VARBINARY data in SQL Server?

INSERT INTO #TempTable(PK, VarBinaryColumn) SELECT PK, VarBinaryColumn FROM dbo. YourPermanentTable; If you need to convert the varbinary data back to the original file text format in T-SQL, you can use CAST or CONVERT to convert to varchar or nvarchar as long as the data was originally ASCII or Unicode.


1 Answers

Actually, you can do this in T-SQL!

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

like image 53
mwigdahl Avatar answered Sep 29 '22 01:09

mwigdahl