title: IF EXISTS conditions within multiple statements joined by a union
body: <p>I have been working on a problem for a few hours and I feel like I'm running in circles.</p>
  
  <p>I am writing a script that will check the a table from and old database to a new one and it wants too see if there are differences in the tables. I have this part done but want to make the output easier to read. I ideally want an output to happen when there are records in the table, signifying there are differences. So if there are differences in tables 1, 4 , and 8 the output will say table 1, table 4, table 8. I will add a snippet of my code but I need to change some stuff because of privacy reasons. </p>
  
  <pre><code>if exists(
  SELECT 'xyz' AS TableName,  1 FROM table1CD 
  LEFT JOIN database2 CL ON CL.X= CAST(CD.X AS VARCHAR(100)) AND CL.Type = 'type1'
  WHERE CL.Type IS NULL
  )
  Select TableName
  Else
  
  UNION
  
  else if exists(
  SELECT 'abc' AS TableName, 1 FROM table3 CA
  LEFT JOIN database2 CL ON CL.X = CAST(CA.Y AS VARCHAR(100)) AND CL.Type = 'type2'
  WHERE CL.Type IS NULL 
  )
  Select TableName
  Else
  
  union
  
  more tables with repeating structure
  </code></pre>
  
  <p>Im still very new with this kinda SQL. I am getting errors when I run this and keep changing it around to try to figure it out but Im at a wall now.</p>