title: String or binary data would be truncated - large strings
body: <p>We have an extremely large nvarchar(max) field that contains html. Within this html is an img tag.</p>
  
  <p>Example:</p>
  
  <pre><code>&lt;img style="float:right" src="data:image/png;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/7gAOQW....
  </code></pre>
  
  <p>The length of this column is 1645151, although what is being replace is a bit less than this, but not a lot.</p>
  
  <p>What we are trying to do, is a replace in SQL on the column:</p>
  
  <pre><code>declare @url varchar(50) = 'myimageurl';
  UPDATE table SET field =
  CAST(REPLACE(CAST(field as NVARCHAR(MAX)),@source,'@url') AS NVARCHAR(MAX))
  </code></pre>
  
  <p>Where @source, is the above image bytes as string, which are assigned to an nvarchar(max) variable before running the replace. and dest is the url of an image, rather than the images bytes as string.</p>
  
  <p>Although I still get the message string or binary data would be truncated. </p>
  
  <p>Does anyone know if this is possible in SQL to replace strings as large as this.</p>