Skip to content

How to Write T-SQL for Picklist Values in Microsoft Dynamics CRM

Getting at the Picklist Values (a.k.a., Option Sets) is not easy.  It’s not hard either.  As you know, the picklist values are stored in the entity as numerical values, not the character-based descriptive values.  But how to get at the descriptive values that are useful to we humans?


Here’s a sample query giving you T-SQL for Picklist Values.  This example is for Leads (ObjectTypeCode 4), and a custom picklist value for County (sync_county).  The key table you want to get access to is the StringMap table.  But you have to put a couple of strategic filters in place to make it work.


SELECT LeadBase.CompanyName, LeadBase.FirstName, LeadBase.LastName, LeadExtensionBase.Sync_County, StringMap.AttributeName, StringMap.Value
LeadExtensionBase ON LeadBase.LeadId = LeadExtensionBase.LeadId INNER JOIN
StringMap ON LeadExtensionBase.Sync_County = StringMap.AttributeValue
WHERE (StringMap.ObjectTypeCode = 4) AND (StringMap.AttributeName = N'sync_county')

Drop us a note

Please drop us a note via the form below with your comments or questions on this blog post; or if there is anything we can help you with.

1 Comment

  1. Nice, thanks!

Add a Comment

Your email address will not be published. Required fields are marked *