title: Condition in SQL server based on first table column value is null
body: <p>I am new in SQL Queries..</p>
  
  <p>I have 2 database DB1 &amp; DB2. </p>
  
  <p>DB1 Contains the table A which has Name,Address &amp; Code columns &amp; DB2 contains the table B which has column Name1,Address1.</p>
  
  <p>if the Code is not null then i want to select Name,Address from the tableA else name1 &amp; address1 should come from tableB.</p>
  
  <p>Please Help me on this.</p>
  
  <pre><code>  select top 1
    a.name 'MyName',
    a.address 'MyAddress'
    from DB1.table1 a
    where a.code &lt;&gt; null
  </code></pre>