title: IF EXISTS, THEN SELECT ELSE INSERT AND THEN SELECT
body: <p>How do you say the following in Microsoft SQL Server 2005:</p>
  
  <pre><code>IF EXISTS (SELECT * FROM Table WHERE FieldValue='') THEN
     SELECT TableID FROM Table WHERE FieldValue=''
  ELSE
     INSERT INTO TABLE(FieldValue) VALUES('')
     SELECT TableID FROM Table WHERE TableID=SCOPE_IDENTITY()
  END IF
  </code></pre>
  
  <p>What I'm trying to do is to see if there is a blank fieldvalue already, and if there is then return that TableID, else insert a blank fieldvalue and return the corresponding primary key.</p>