简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM