Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Query Expression or Fetch Xml - Equivalent of NOT EXISTS SQL

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi, I am trying to translate the following SQL query into a query expression or a fetch XML. I know I can get the Raw data from the Opportunity Entity and use LINQ queries to filter out what I need but I would like to know if there is a way to get it done using a query expression or a fetch XML.

SELECT o.OpportunityId
FROM dbo.Opportunity o
WHERE NOT EXISTS
(
    SELECT cbo.New_OpportunityId
    FROM dbo.New_commission cbo
        INNER JOIN dbo.New_commissionreport cr
            ON cr.New_commissionreportId = cbo.New_CommissionReportId
    WHERE cbo.New_OpportunityId = o.opportunityid
          AND cbo.New_Type = 1 -- type new
          AND (cr.New_CommissionPeriodFrom
          BETWEEN '20181001' AND '20181031'
              )
);


Please advise.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Query Expression or Fetch Xml - Equivalent of NOT EXISTS SQL

    Thanks for taking time to help. I could not build what I needed in Advanced Find or Fetch XML and ending up getting the raw data from Opportunity Entity and then applied filter.

    Thanks,

    Sridhar

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Query Expression or Fetch Xml - Equivalent of NOT EXISTS SQL

    I would suggest to try to build yoru query using advance find and then you can download the fetchxml.

    us.hitachi-solutions.com/.../great-fetchxml-tool-for-microsoft-dynamics-crm

    Hope this helps.

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 1,014 Super User 2024 Season 2 on at
    RE: Query Expression or Fetch Xml - Equivalent of NOT EXISTS SQL

    Hi SridharV86,

    You cannot use the NOT EXISTS operator in FetchXML or QueryExpression.

  • Suggested answer
    pavanmanideep Profile Picture
    pavanmanideep 1,329 on at
    RE: Query Expression or Fetch Xml - Equivalent of NOT EXISTS SQL

    Hi Sridhar,

    Please use the below tool to convert your SQL queries to Fetch XML

    SQL TO FetchXML

    However due to limitations of CRM Fetch XML, all the SQL query... Try to start with smaller query and start adding additional conditions while using this tool..

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,569 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans