title: Why won't this SQL CAST work?
body: <p>I have a <code>nvarchar(50)</code> column in a SQL Server 2000 table defined as follows:</p>
  
  <pre><code>TaskID nvarchar(50) NULL
  </code></pre>
  
  <p>I need to populate this column with random SQL GUID's using the <code>NEWID()</code> function (I am unable to change the column type to <code>uniqueidentifier</code>).</p>
  
  <p>I tried this:</p>
  
  <pre><code>UPDATE TaskData SET TaskID = CAST(NEWID() AS nvarchar)
  </code></pre>
  
  <p>but I got the following error:</p>
  
  <blockquote>
    <p>Msg 8115, Level 16, State 2, Line 1 
    Arithmetic overflow error converting
    expression to data type nvarchar.</p>
  </blockquote>
  
  <p>I also tried:</p>
  
  <pre><code>UPDATE TaskData SET TaskID = CAST(NEWID() AS nvarchar(50))
  </code></pre>
  
  <p>but then got this error:</p>
  
  <blockquote>
    <p>Msg 8152, Level 16, State 6, Line 1 
    String or binary data would be
    truncated.</p>
  </blockquote>
  
  <p>I don't understand why this doesn't work but this does:</p>
  
  <pre><code>DECLARE @TaskID nvarchar(50)
  SET @TaskID = CAST(NEW() AS nvarchar(50))
  </code></pre>
  
  <p>I also tried <code>CONVERT(nvarchar, NEWID())</code> and <code>CONVERT(nvarchar(50), NEWID())</code> but got the same errors.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Ok, my eyesight is going, the column size on the table is <code>nvarchar(32)</code> not 50. Deepest apologies for the timewasting and thanks for all the answers. </p>