web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

AP SQL script to look for orphaned records

(0) ShareShare
ReportReport
Posted on by 75,848 Moderator

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:
I have the same question (0)
  • Suggested answer
    Andrea Melroe Profile Picture
    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!

  • Richard Wheeler Profile Picture
    75,848 Moderator 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.

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

    Hi Richard,

    Glad to hear the problem is resolved!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans