Sql Server Query to Get the Option Set label name

In some of our requirements we may need to query the Option set label name from the back end Sql Server.

For this we need to Query the StringMap table in CRM DB.

Query to get the columns from StringMap table will be Select * from StringMap .


In order to get option set label name we need to pass the AttributeValue ,ObjectTypeCode,AttributeName.

for eg : if you want to get the gendercode option set label name in Contact entity need to pass the AttributeValue =’1′ ,ObjectTypeCode=’2′,AttributeName=’gendercode ‘.

Total query is as follows.
select cn.LastName,cn.New_age,cn.New_Nationality,sm.Value as Gender
from Contact cn LEFT JOIN [Orgname_MSCRM].dbo.StringMap sm On sm.AttributeValue=’1′ AND sm.ObjectTypeCode=2 AND sm.AttributeName=’gendercode’ AND sm.LangId=’1033′.

Hope this will helps you.





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s