title: Using datalength(varbinary datatype) in substring
body: <p>I am trying to select some varbinary data from TABLE(DATA varbinary(2048)) to my .NET dll without any padding. All my records are currently 64 bytes long but they may vary in the future.</p>
  
  <p>I use a stored procedure that does this: </p>
  
  <pre><code> select substring(DATA, 1, datalength(DATA)) as DATA from TABLE
  </code></pre>
  
  <p>I would expect this to work but the stream I get in my dll is 2050(2048 + 2) bytes long. </p>
  
  <p>When I hard code the value (<code>select substring(DATA, 1, 64) as DATA from TABLE</code>) it returns 66 bytes as I would expect.</p>
  
  <p>Am I missing something (obvious)?</p>