title: Generate a sequence number, skipping null values
body: <p>I would like to generate a sequence number that skips null values (i.e. null values are NOT counted):</p>
  
  <pre><code>PAT_ID ENC_DATE  SEQ
  ------ --------  ---
  1      null      null
  1      05/01/15  1
  2      01/01/14  1
  2      null      null
  2      02/11/14  2
  </code></pre>
  
  <p>Currently:</p>
  
  <pre><code>SELECT  PAT_ID, ENC_DATE
          ,case when enc_date is not null then ROW_NUMBER() OVER (PARTITION BY pat_id ORDER BY end_date) end SEQ
  </code></pre>
  
  <p>Generates (a null value increments the SEQ value):</p>
  
  <pre><code>PAT_ID ENC_DATE  SEQ 
  ------ --------  ----
  1      null      null
  1      05/01/15  2   
  2      01/01/14  1   
  2      null      null
  2      02/11/14  3   
  </code></pre>
  
  <p>What am I missing?</p>