title: CRM 2011 - SQL Query to retrieve text of option set?
body: <p>I am trying to write the query to retrieve the data from the Contact table. So, let us say I want the following fields </p>
  
  <p>FirstName, LastName and Gender. </p>
  
  <p>Now, the field for gender is gendercode, which is an option set and this data resides in StringMapBase. </p>
  
  <p>What would the query to return the text value of gendercode?</p>
  
  <p>I could write this, but surely there is a better way to write. </p>
  
  <pre><code>SELECT FirstName, LastName, GenderCode FROM Contact
  </code></pre>
  
  <p>For retrieving the text value</p>
  
  <pre><code>SELECT FirstName, LastName, GenderCode, sm.Value as Gender FROM Contact c, StringMap sm
  WHERE c.GenderCode = sm.AttributeValue
  AND sm.AttributeName = 'gendercode'
  </code></pre>
  
  <p>Any suggestions?</p>