|
| 1 | +--- |
| 2 | +title: "Use column comparison in queries (Common Data Service) | Microsoft Docs" # Intent and product brand in a unique string of 43-59 chars including spaces |
| 3 | +description: "Learn how to compare columns when querying business data." # 115-145 characters including spaces. This abstract displays in the search result. |
| 4 | +ms.custom: "" |
| 5 | +ms.date: 07/08/2020 |
| 6 | +ms.reviewer: "pehecke" |
| 7 | +ms.service: powerapps |
| 8 | +ms.topic: "article" |
| 9 | +author: "NHelgren" # GitHub ID |
| 10 | +ms.author: "nhelgren" # MSFT alias of Microsoft employees only |
| 11 | +manager: "mayadu" # MSFT alias of manager or PM counterpart |
| 12 | +search.audienceType: |
| 13 | + - developer |
| 14 | +search.app: |
| 15 | + - PowerApps |
| 16 | + - D365CE |
| 17 | +--- |
| 18 | + |
| 19 | +# Use column comparison in queries |
| 20 | + |
| 21 | +In the Common Data Service, users can perform a column comparison for the |
| 22 | +following condition operators using FetchXML, Web API, or the SDK API: |
| 23 | + |
| 24 | +- Equal |
| 25 | +- NotEqual |
| 26 | +- GreaterThan |
| 27 | +- GreaterEqual |
| 28 | +- LessThan |
| 29 | +- LessEqual |
| 30 | + |
| 31 | +This will allow the comparison of an attribute against a specific value and |
| 32 | +return all found records, or allow the comparison of two attributes to return |
| 33 | +all records with a matching value. |
| 34 | + |
| 35 | +## Limitations |
| 36 | + |
| 37 | +Listed below are the limitations for the current Common Data Service column comparison support. |
| 38 | + |
| 39 | +- Only two columns may be compared at a time. |
| 40 | +- Multi-value condition operators are not supported (i.e., "in"). |
| 41 | +- Extended condition operators are not supported (i.e., "creditlimit \> spends+1000"). |
| 42 | +- Incompatible attribute comparison is not supported. For example, "int vs. int" attributes is a valid comparison but "int vs. string" attributes is not valid comparison. |
| 43 | + |
| 44 | +## Column comparison using FetchXML |
| 45 | + |
| 46 | +The following example shows how to compare columns using FetchXML: |
| 47 | + |
| 48 | +```xml |
| 49 | +<fetch> |
| 50 | + <entity name='contact' > |
| 51 | + <attribute name='firstname' /> |
| 52 | + <filter> |
| 53 | + <condition attribute='firstname' operator='eq' valueof='lastname'/> |
| 54 | + </filter> |
| 55 | + </entity> |
| 56 | +</fetch> |
| 57 | +``` |
| 58 | + |
| 59 | +For FetchXML requests, a new node `valueof` has been added inside the condition |
| 60 | +node. The `valueof` tag is used to identify the attribute that is being compared |
| 61 | +to the selected attribute. In the above example, the 'firstname' column is being |
| 62 | +compared against the 'lastname' column and will return any records that contain |
| 63 | +the same value across both attributes. |
| 64 | + |
| 65 | +### See Also |
| 66 | + |
| 67 | +[Use FetchXML to construct a query](use-fetchxml-construct-query.md) |
| 68 | +[Column comparison using the Web API](webapi/query-data-web-api.md#column-comparison-using-the-web-api) |
| 69 | +[Column comparison using the SDK API](org-service/use-conditionexpression-class.md#column-comparison-using-the-sdk-api) |
0 commit comments