title: nested If in select
body: <p>How can I combine these two queries?</p>
  
  <pre><code>select e.UserId, count(*) as [Registrations], min(uas.UserId), min(uas.[TimeStamp])
  from Ev as e 
      left join UAS as uas on e.UserId = uas.UserId
  where e.EventTypeId = 3 and e.Value is not null 
  group by e.UserId 
  having count(*) &gt;= 10
  
  if not exists (select * from Ev as e left join UAS as uas
                     on e.UserId = uas.UserId where uas.UserId = e.UserId)
  begin
      insert UAS values (12, '2013-05-31 15:54:14.963')
  end;
  </code></pre>
  
  <p>I want that if that UserId doesn't exist in UAS table insert it.</p>