SQL Server 2014 Hashbytes of a nvarchar(max) result is nvarchar(max)
<p>Using SQL Server 2014 I have a table that has a <code>nvarchar(max)</code> column called <code>[ASCII File]</code> which can contain an ASCII text file of many K. I then want to do a MD5 hashbytes on that file and the resultant hash should always be 20 bytes.</p>

<p>Well when I do a select of <code>hashbytes('MD5', [ASCII File])</code> I get query completed with errors</p>

<blockquote>
  <p>Msg 8152, Level 16, State 10, Line 4<br>
  String or binary data would be truncated.</p>
</blockquote>

<p>I get the same message when I try </p>

<pre><code>left(hashbytes('MD5', [ASCII File]), 50)
</code></pre>

<p>I get the same message when I try </p>

<pre><code>convert(varchar(50), hashbytes('MD5', [ASCII File]))
</code></pre>

<p>It seems like since the column I am doing the hashbytes on is <code>nvarchar(max)</code>, the result of the hashbytes function also is <code>nvarchar(max)</code>.</p>

<p>Can you tell me how I can get the result to be the expected 20 long and not something so long it has to be truncated? </p>