The views and opinions expressed in this blog are those solely of the author(s) and do not necessarily reflect Microsoft’s current policy, position, or branding. For official announcements and guidance on Dynamics 365 apps and services, please visit the Microsoft Dynamics 365 Blog.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2020 release wave 1 Discover the latest updates and new features to Dynamics 365 planned through September 2020
Release overview guides and videos Release Plan | Preview 2020 Release Wave 1 Timeline
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Upcoming TechTalks
Dynamics CRM works largely on FetchXML queries. FetchXML is a proprietary query language for Dynamics CRM. For developers coming from SQL background, they would really want to find the SQL query that the FetchXML translates into. While one way is to explain the FetchXML syntax, it might help to also get the SQL statement that the CRM Platform converts into.
SQL Tracing is what comes to the rescue here. Using SQL Tracing, you can find all the SQL queries that get executed in the background when running CRM application.
Note: SQL Tracing can only be executed for CRM On-Premise systems.
Take an example where we have a below Fetch XML based query that is generated using advance find.
<fetch version=”1.0″ output-format=”xml-platform” mapping=”logical” distinct=”false”>
<attribute name=”name” />
<attribute name=”primarycontactid” />
<attribute name=”telephone1″ />
<attribute name=”accountid” />
<order attribute=”name” descending=”false” />
<condition attribute=”createdon” operator=”last-x-years” value=”4″ />
Follow the below steps to get the SQL Query for the above.
To create a new trace click on File -> New Trace.
In this way you will get the SQL query from the fetch XML.
exec sp_executesql N’select
top 51 “account0″.Name as “name”
, “account0″.PrimaryContactId as “primarycontactid”
, “account0″.Telephone1 as “telephone1″
, “account0″.AccountId as “accountid”
, “account0″.PrimaryContactIdName as “primarycontactidname”
, “account0″.PrimaryContactIdYomiName as “primarycontactidyominame”
Account as “account0″ (NOLOCK)
(( “account0″.CreatedOn >= @CreatedOn0 and “account0″.CreatedOn <= @CreatedOn1 )) order by
, “account0″.AccountId asc’,N’@CreatedOn0 datetime,@CreatedOn1 datetime’,@CreatedOn0=’2010-05-03 07:00:00′,@CreatedOn1=’2014-05-03 11:52:49.553′
You can see from the SQL query, there is hardcoded date for condition i.e. Created on date on Last X Year.
There are built in SQL functions to query CRM data. In this case you can use “dbo.fn_LastXYear(<date>,<number of year>)”.
Use this to understand the SQL query behind any CRM operation performed from the UI.
To generate FetchXML for a SQL query you have in hand you can use the online tool available athttp://www.sql2fetchxml.com/ from KingswaySoft
Business Applications communities