Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

FetchXML conversion to sql query is missing some values

Posted on by Microsoft Employee

I have the following FetchXML statement and sql query.

The query is not returning the actual values for the filter conditions, such as the 100000012 from the it_semesteroperational condition node.

the query returns the exact number of rows I would expect, but the values are all null.

Any ideas?

Thanks,

Michael

DECLARE @xml XML

SET @xml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="it_grtproduct">
            <attribute name="it_grtproductid"/>
            <attribute name="it_titleworkingtitle"/>
            <attribute name="it_1stauthor"/>
            <attribute name="it_devphase"/>
            <attribute name="it_amarc"/>
            <attribute name="it_pdctotalforecast"/>
            <attribute name="it_pdcannualtotal"/>
            <attribute name="it_pdcoctforecast"/>
            <attribute name="it_pdcnovforecast"/>
            <attribute name="it_pdcdecforecast"/>
            <attribute name="it_pdcmayforecast"/>
            <attribute name="it_pdcmarforecast"/>
            <attribute name="it_pdcjunforecast"/>
            <attribute name="it_pdcjulforecast"/>
            <attribute name="it_pdcjanforecast"/>
            <attribute name="it_pdcfebforecast"/>
            <attribute name="it_pdcaugforecast"/>
            <attribute name="it_pdcaprforecast"/>
            <attribute name="it_pdcsepforecast"/>
            <order attribute="it_amarc" descending="false"/>
            <filter attribute="FitlerName" type="and">
            <condition attribute="it_devphase" operator="in">
                  <value>100000000</value>
                  <value>100000001</value>
            </condition>
            <condition attribute="statecode" operator="eq" value="0"/>
            <condition attribute="it_semesteroperational" operator="in">
                        <value>100000012</value>
                        <value>100000014</value>
                        <value>100000013</value>
                        <value>100000015</value>
                        <value>100000002</value>
                        <value>100000005</value>
                        <value>100000008</value>
                        <value>100000011</value>
                        <value>100000000</value>
                        <value>100000003</value>
                        <value>100000006</value>
                        <value>100000009</value>
                        <value>100000001</value>
                        <value>100000004</value>
                        <value>100000007</value>
                        <value>100000010</value>
                        <value>100000017</value>
                        <value>100000018</value>
                        <value>100000016</value>
                        <value>100000025</value>
                        <value>100000019</value>
                        <value>100000024</value>
                        <value>100000020</value>
                        <value>100000021</value>
                  </condition>
                  <condition attribute="it_1stauthor" operator="not-null"/>
            </filter>
      </entity>
</fetch>  '

SELECT cc.c.value('@attribute', 'varchar(100)') as [condition]
, v.d.value('@value', 'varchar(100)') as [Value]

FROM @xml.nodes('fetch') f(c)
      CROSS APPLY f.c.nodes('entity') e(c)
            CROSS APPLY e.c.nodes('filter') g(c)
            cross apply g.c.nodes('condition') cc(c)
            cross apply cc.c.nodes('value') v(d)



*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans