Queries
Queries are business entities that define the parameters and criteria of a Microsoft CRM database search. Queries support cross-entity searches.
In Microsoft CRM 3.0 there are two entities available for queries against the Microsoft CRM database. The UserQuery and SavedQuery entities are appropriate for frequently used queries that span entity types and queries that perform aggregation.
A UserQuery is owned by an individual user, can be assigned and shared with other users, and can be viewed by other users depending on the query's access privileges. A SavedQuery is owned by an organization making it visible to all users in the organization.
Both entities support the proprietary FetchXML query language. While at first glance this may seem more powerful, especially for developers used to constructing queries in SQL, using the Retrieve or RetrieveMultiple methods will have better performance. This is due to the parsing and validation of the Fetch XML. In addition to using FetchXML to construct and execute queries against the database, you can easily build queries using the query builder class QueryExpression.
A query that contains a FetchXML statement is constructed and then assigned to the appropriate attribute in either a userquery or savedquery depending on the type of query being executed. Both types of queries can be executed by the ExecuteFetch message or using the ExecuteByIdSavedQuery or ExecuteByIdUserQuery messages.
Both user and saved queries can be stored in the Microsoft CRM database and referred to by ID. These stored queries are shown in the Advanced Find section of the Microsoft CRM application and also in the View drop-down list of an entity. Queries can be imported and exported using the Import/Export capability of the Microsoft CRM application.
The following messages are useful for working with queries.
| Message | Description |
| FetchXmlToQueryExpression | Use this message to convert a query in FetchXML language to a QueryExpression. |
| QueryExpressionToFetchXml | Use this message to convert a query in QueryExpression format to one expressed in the FetchXML language. |
In This Topic
UserQuery
SavedQuery
Related Topics
Building Queries
Fetch XML schema
QueryExpression
QueryByAttribute
© 2007 Microsoft Corporation. All rights reserved.