Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

AP SQL script to look for orphaned records

(0) ShareShare
ReportReport
Posted on by 75,730

Does anyone have a SQL script that will identify AP SQL script to look for orphaned records? I was using the AP Inquiry screen and noticed that several vendors cause this screen to crash. I suspect there are missing records in the AP tables.

Categories:
  • Andrea Melroe Profile Picture
    Andrea Melroe 3,437 on at
    RE: AP SQL script to look for orphaned records

    Hi Richard,

    Glad to hear the problem is resolved!

  • Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at
    RE: AP SQL script to look for orphaned records

    I ran check links after deleting the records from the PM00400 table. The remaining problem was the next payment number in AP setup had not gotten updated so when they went to enter a new manual payment it tried to use an existing number.

  • Suggested answer
    Andrea Melroe Profile Picture
    Andrea Melroe 3,437 on at
    RE: AP SQL script to look for orphaned records

    Hi Richard,

    Here are some scripts I use to find invalid orphan records in payables:

    SELECT * FROM PM00400 WHERE (DCSTATUS = 0 OR DCSTATUS = '' OR DOCTYPE = '' OR DOCTYPE = 0 OR DOCNUMBR = '' OR CNTRLNUM = '' OR VENDORID = '') AND DCSTATUS <> 1

     

    SELECT * FROM PM10300 WHERE DOCTYPE = '' OR DOCTYPE = 0 OR VCHRNMBR= '' OR VENDORID = ''

     

    SELECT * FROM PM10400 WHERE DOCTYPE = '' OR DOCTYPE = 0 OR VCHRNMBR= '' OR VENDORID = '' OR DOCNUMBR = ''

     

    SELECT * FROM PM10100 WHERE VCHRNMBR = '' OR VENDORID = ''

     

    SELECT * FROM PM20000 WHERE DOCTYPE = '' OR DOCTYPE = 0 OR VCHRNMBR= '' OR VENDORID = '' OR DOCNUMBR = ''

     

    SELECT * FROM PM10200 WHERE DOCTYPE = '' OR DOCTYPE = 0 OR VCHRNMBR= '' OR VENDORID = '' OR APFRDCNM = '' OR APTODCNM = '' or APTVCHNM = ''

     

    SELECT * FROM PM30200 WHERE DOCTYPE = '' OR DOCTYPE = 0 OR VCHRNMBR= '' OR VENDORID = '' OR DOCNUMBR = ''

     

    SELECT * FROM PM30300 WHERE DOCTYPE = '' OR DOCTYPE = 0 OR VCHRNMBR= '' OR VENDORID = '' OR APFRDCNM = '' OR APTODCNM = '' or APTVCHNM = ''

     

    SELECT * FROM PM30600 WHERE VCHRNMBR = '' OR VENDORID = ''

    If there are records missing (like the PM00400 keys record – this is what I find is most commonly missing), it makes sense to run check links (in test) to let GP repopulate those for you.

    Hope this helps!

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans