Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

SQL to FetchXML

Posted on by Microsoft Employee

Hello,

Can you please help me to how to convert below SQL Server code to FetchXML?

I want to create SQL server job by Deploying SSIS Package. Job will execute every day and i want to retain only last 30 days data from current date.

DELETE
FROM TABLE_P
WHERE CREATEDON < CAST(DATEADD(day, -30, GETDATE())  AS date)

*This post is locked for comments

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: SQL to FetchXML

    Hi,

    you can take a look below article. but you have to modify the date to suit your needs.

    docs.microsoft.com/.../gg327533(v=crm.8)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SQL to FetchXML

    Hello, The table contains huge number of records (table name: exceptionlog table, it contains all audit data). Now i have to retain only last 30 days data and i have to remove all old audit data. so i have prepared above sql query to achieve this. Is there any other way to achieve this instead of sql query?

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: SQL to FetchXML

    Hi Srinivas ,

    Is there any specific reason you want to delete data using FetchXML ?

    FetchXML used for data retrieval and not for deletion. I believe you are aware that there is OOB functionality called Bulk Deletion , you can define the condition and delete data as per your needs.

    Check here -

    docs.microsoft.com/.../delete-bulk-records

    www.powerobjects.com/.../recurring-bulk-deletion-in-dynamics-crm-2011

    crmtipoftheday.com/.../bulk-delete

    If you want to delete data using code you may check  below reference -

    docs.microsoft.com/.../sample-execute-multiple-requests

    docs.microsoft.com/.../sample-create-retrieve-update-delete-late-bound

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: SQL to FetchXML

    Hi,

    FetchXML does not support for delete. Furthermore, you shouldnt delete the records directly using SQL, this is unsupported.

    To delete the record,

    1. Construct your query to get all related records.

    docs.microsoft.com/.../use-fetchxml-construct-query

    2. Execute Delete request.

    - docs.microsoft.com/.../sample-create-retrieve-update-delete-late-bound

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,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans