Generic SQL Error – RetriveMultiple with ConditionOperator.Contains in CRM

Today someone “me” wanted to change the requirements of the wrap I have over the CRM web services so I could reuse the method more often, but to do so I need to transform the method more standard. So I changed the ConditionOperator.Equal to ConditionOperator.Contains. But was giving me an error “Generic SQL Error” while using in the ConditionExpression. The requirement was to get all the records from an entity that contains a specific field with a certain attribute value.

Before, using Equal:

Microsoft.Xrm.Sdk.Query.ConditionExpression condition = new Microsoft.Xrm.Sdk.Query.ConditionExpression(FieldName), Microsoft.Xrm.Sdk.Query.ConditionOperator.Equal, AttributeValue);

After, using Contains: You need to add % to the attributevalue but don’t work if the table or indexed view is not full-text indexed, therefore you need to use Like.

Microsoft.Xrm.Sdk.Query.ConditionExpression condition = new Microsoft.Xrm.Sdk.Query.ConditionExpression(FieldName), Microsoft.Xrm.Sdk.Query.ConditionOperator.Contains, “%”+AttributeValue+“%”);

After, using Like: You need to add % to the attributevalue

Microsoft.Xrm.Sdk.Query.ConditionExpression condition = new Microsoft.Xrm.Sdk.Query.ConditionExpression(FieldName), 
Microsoft.Xrm.Sdk.Query.ConditionOperator.Like, “%”+AttributeValue+“%”);


Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di

Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...