title: selecting from either of two columns in SELECT
body: <p>In SQL Server 2008R2 I have two tables, <code>CONFIG_DATA</code> and <code>CNA_LIST</code>:</p>
  
  <p><code>CONFIG_DATA</code> has two fields: </p>
  
  <pre><code>ID [varchar(20)]    Address [int]
  01                  141516  
  02                  132132
  </code></pre>
  
  <p><code>CNA_LIST</code> has three fields: </p>
  
  <pre><code>Address [int]  IP1 [varchar(20)]   IP2 [varchar(20)]
  141516         1.2.3.4             (null)
  132132         (null)              2.3.4.5
  </code></pre>
  
  <p>These are field devices that have one or two IP addresses, in the <code>IP1</code> or <code>IP2</code> field (can be either, or both).</p>
  
  <p>I would like to list the <code>CONFIG_DATA</code> table with <code>IP1</code> from the <code>CNA_LIST</code> table, and if it's <code>NULL</code>, the <code>IP2</code>.</p>
  
  <p>The <code>Address</code> field links the two tables.  </p>
  
  <p>this would work fine:</p>
  
  <pre><code>select a.ID, a.Address, b.IP1
  from CONFIG_DATA a, CNA_LIST b where a.Address = b.Address
  </code></pre>
  
  <p>but if <code>IP1</code> is <code>null</code> I need <code>IP2</code>, with this column listed as <code>"IP"</code>:</p>
  
  <p>I've tried <code>IF(b.IP1 &lt;&gt; '')b.IP1 ELSE b.IP2</code> but the syntax checker complains.</p>