1
votes

I'm using Microsoft Dynamics CRM 2016 On Premise, I'm trying to get some specific metadata, basically get through SQL Server the field physical name, display name(Label) and the field value from a given entity. This is the query I have so far:

 select  a.PhysicalName, I.Label
 from  [dbo].[Attribute] a
 inner join [dbo].[Entity] e on e.EntityId=a.EntityId
 inner join [dbo].[LocalizedLabel] l on l.ObjectId = a.AttributeId
 where e.Name='DesiredEntityName'

With this query I can get the fields and displayed label from the given entity, however I don't see the way on how to join and get the list of values for each field.

1
Are you looking for optionset aka picklist values? Then look at stringmap table. - Arun Vinoth - MVP
I need all fields (physical names) from a specified entity (table) plus displayed names (Labels) and their values, not optionset vales. - Poyson1

1 Answers

0
votes

You have to query from stringmap table where all the picklist (optionset) values will be stored.

SELECT AttributeValue as Value, Value as Label
FROM StringMap s
JOIN EntityLogicalView e on s.ObjectTypeCode = e.ObjectTypeCode
WHERE AttributeName = 'DesiredAttributeName'
AND e.Name = 'DesiredEntityName'
ORDER BY DisplayOrder

Retrieve Option Set Metadata Via SQL

Edit:

I see what you want now. You basically need to mimic what Product is doing when you export the data to Excel.

When you do the below query using database table or view or filtered view, you want the display name as ALIAS.

SELECT name AS [Account Name], telephone1 AS [Business Phone]  from Account

The problem would be that Schema Name telephone1 is readily available in table where Account records data is stored, whereas Display Name Business Phone is stored in multiple different tables like Entity, Attribute, LocalizedLabel.

You may have to do your own view or query concatenation to achieve this.