title: SQL Server: I am getting an error while altering view when I try to add some virtual column which in turn based on virtual column
body: <p>I have 20 databases, each with same table but different columns.</p>
  
  <p>So to make the uniform we are creating views on top of each table in a database which will contain all the columns, as there will be one application accessing all the database.</p>
  
  <p>In the view, I have to write the query in such a way that if I want to alter it and add any addition column for testing I should be able to do that.</p>
  
  <p>Now in below query I am altering / creating query such that it takes all the columns of that table from the database, and then I append the other columns which are not present in it.</p>
  
  <p>I need to add a column which will just concatenate some of the columns</p>
  
  <pre><code>ALTER VIEW [dbo].[AIV_PARKING]
  AS
      SELECT 
          *,
          Cast(NULL AS [VARCHAR](20)) [ACTCODE],
          Cast(NULL AS [VARCHAR](1)) [ACTIVATEINFO],
          Cast(NULL AS [VARCHAR](20)) [VEHLICNOCHECK],
          Cast(NULL AS [VARCHAR](40)) [ACTIVITY],
          Cast(Isnull(vehlicnocheck, '') + '|' + 
               Isnull(officername, '') + '|' + 
               Isnull(locstreet, '') + '|' + 
               Isnull(locsideofstreet, '') + '|' + 
               Isnull(loccrossstreet1, '') + '|' + 
               Isnull(loccrossstreet2, '') + '|'
                + Isnull(locsuburb, '') + '|'
                + Isnull(locstate, '') + '|'
                + Isnull(locpostalcode, '') + '|'
                + Isnull(loclot, '') + '|'
                + Isnull(locpostalcode, '') + '|'
                + Isnull(Cast(officerid AS VARCHAR(20)), '') 
                + Isnull(officername, '') + '|'
                + Isnull(Cast (issueno AS VARCHAR(100)), '') AS NVARCHAR(max)) AS SearchText
      FROM   
          [dbo].parking 
  </code></pre>
  
  <p>Here I added a column called <code>SearchText</code> which concatenates other columns, but I get an error </p>
  
  <blockquote>
    <p>Invalid column name 'VehLicNoCheck'</p>
  </blockquote>
  
  <p>Is there any way I can add this column to this view?</p>
  
  <p>I also tried to do to something below but I got the same error:</p>
  
  <pre><code>CAST(CASE 
     WHEN NOT EXISTS
     (
         Select 1 from INFORMATION_SCHEMA.COLUMNS
         Where Column_name ='VehLicNoCheck'
           and table_name='Parking'
     )
     THEN ''
     ELSE ISNULL(VehLicNoCheck,'')
     END as nvarchar(max)
  )
  </code></pre>