Kanini Kanini - 1 year ago 75
SQL Question

CRM 2011 - SQL Query to retrieve text of option set?

I am trying to write the query to retrieve the data from the Contact table. So, let us say I want the following fields

FirstName, LastName and Gender.

Now, the field for gender is gendercode, which is an option set and this data resides in StringMapBase.

What would the query to return the text value of gendercode?

I could write this, but surely there is a better way to write.

SELECT FirstName, LastName, GenderCode FROM Contact

For retrieving the text value

SELECT FirstName, LastName, GenderCode, sm.Value as Gender FROM Contact c, StringMap sm
WHERE c.GenderCode = sm.AttributeValue
AND sm.AttributeName = 'gendercode'

Any suggestions?

Answer Source

Use the filtered views for reading from the DB. Fully supported and gives you what you need without jumping through hoops and creating joins.

SELECT firstname, lastname, gendercodename from FilteredContact
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download