Calculating stored bytes of data in a varbinary(MAX) field

  • I am using sql server 2005 with asp.net. I am storing images in a varbinary(max) field. I would like to find out the amount of bytes stored in the field. For example, if I put a 30kb file in the field, is there a function in sql server 2005 to tell me that the field has 30kb of data?

    Thanks,

    Ron

  • damn that is interesting...my first instinct was that the len() function would work on a varchar(max), but it just returns 8000 if it is too big: I'll look some more.....

    create table tmp(val varchar(max))

    insert into tmp(val)

    select replicate('12345',32767) UNION

    select replicate('xrtg',41527)

    select len(val) from tmp --select datalength(val) from tmp --same behavior

    results:

    8000

    8000

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply