title: SQL Union? or other method
body: <p>I am using SQL Server 2008 and Talend </p>
  
  <p>The problem that I am facing is, I have two tables in two different Databases, they have the same fields and I am trying to query them and have certain criteria met. </p>
  
  <p>The user has the correct privileges to view both tables and all. </p>
  
  <p>Both tables I just need a few fields, so I created views to make life easier:
  Db USA I created a view</p>
  
  <p>(IN THE VIEW)</p>
  
  <pre><code>"SELECT IDCUST, NAMECUST,CODETERM,AMTCRLIMT,DATELASTIV,AMTBALDUEH
  FROM TABLE!
  WHERE COUNTRYCODE = 'USA' OR COUNTRYCODE ="U.S.A" //this is for USA server 
  only the other doesn't have the WHERE clause. 
  </code></pre>
  
  <p>Now what I want to do is query this view with my other DB ('MAIN').</p>
  
  <p>The Criteria is if the IDCUST is the same then I just want the row from 'USA' Database.</p>
  
  <p>I Tried: </p>
  
  <pre><code>SELECT *  
  FROM USA.dbo.VIEWUSA 
  UNION 
  SELECT *  
  FROM MAIN.dbo.VIEWMAIN
  WHERE MAIN.dbo.IDCUST &lt;&gt; USA.dbo.VIEWUSA.IDCUST
  </code></pre>
  
  <p>It has an error though saying USA.dbo.VIEWUSA.IDCUST was not appropriate. </p>
  
  <p>I tried it as a JOIN but my join did not work at all (the max rows was around 6k and it was querying at 100k before i stopped it.)</p>