In SQL Server 2005 and 2008 R2, I'm calling into a stored procedure that has an out parameter defined as varbinary(max)
. The out parameter returns 10020 bytes according to DATALENGTH
.
However, SQL Server errors if I try to define a varbinary with > 8000 bytes such as varbinary(10000). E.g.
The size (10000) given to the type 'varbinary' exceeds the maximum allowed for any data type (8000).
What is happening here? How can SQL Server return more bytes than allowed in the data type? Is SQL Server using some other data type behind the scenes to hold > 8000 bytes?
varbinary(max)
or avarbinary(8000)
but you can't define avarbinary
with a size between 8000 and max (2^31 - 1). Avarbinary(max)
can have a 10,000 byte value, avarbinary(8000)
cannot.