title: Conversion failed when converting the varchar value 'NULL' to data type int. Why?
body: <p>I am trying to add a new column called <code>[Scanned]</code> to my SQL Server table, <code>[master].[dbo].[TEST_concat]</code>.</p>
  
  <p>However, I get this error:</p>
  
  <blockquote>
    <p>Msg 245, Level 16, State 1, Line 2<br>
    Conversion failed when converting the varchar value 'NULL' to data type int.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>SELECT TOP (11000) 
      filer_id
      ,[filerName]
      ,[ResourceName]
      ,[UniqueIdentity]
      ,[DirID]
      ,[DirsCount]
      ,[PermCount]
      ,[RowID]
      ,[ResourceType]
      ,[ResourceFlags]
      ,[Hresult]
      ,[Details]
      ,[fsid]
      ,[Protocol]
      ,[vExport]
      ,[filerType]
      ,[Error Messages]
  FROM 
      [master].[dbo].[TEST_concat]
  
  ALTER TABLE dbo.TEST_concat
  ADD [Scanned] AS
      CASE WHEN [DirID] &gt; 0 AND [DirsCount] IS NULL 
              THEN 'in Shares table, but not SortedDirectoryTree properties'
           WHEN [DirID] &gt; 0 AND  [DirsCount] &gt; 0 
              THEN 'Yes'
           WHEN [DirID] IS NULL AND [DirsCount] IS NULL
              THEN 'No'
           ELSE ' ' 
      END
  </code></pre>
  
  <p>This is what my results look like with the error message:</p>
  
  <p><a href="https://i.stack.imgur.com/V9G7Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V9G7Q.png" alt="enter image description here"></a></p>
  
  <p>The results should be all filled out with thousands of lines.</p>