Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

SQL Code to Identify Inactive Orders

(0) ShareShare
ReportReport
Posted on by 5,985

Hi All,

I am trying to write a select statement that is designed to pull information about SOP Orders and Invoices that haven't had the document or associated note updated in a set number of days. I also want to exclude orders that have a value other than null or 01/01/1900 in an extender window. I think I am missing something to due with nested where clauses but am having trouble figuring out exactly what it is.

Situation 1. Document hasn't been modified and the note hasn't been updated in 5 days. Display.

Situation 2. Document hasn't been modified and the note hasn't been updated in 5 days but there is a value other than null or 01/01/1900 in the E.[Must Ship By] column. Don't display.

Situation 3. Document or note has been updated in the last 5 days. Don't display.

My code so far.

select
S.sopnumbe,
S.CUSTNMBR,
S.DOCDATE,
S.BACHNUMB,
S.MODIFDT,
N.TXTFIELD,
N.DATE1,
E.[SOP Number],
E.[Must Ship By]
from SOP10100 S
inner join SY03900 N
ON S.NOTEINDX = N.NOTEINDX
left outer join JR_EXT_TKR1 E
ON S.SOPNUMBE = E.[SOP Number]
where s.MODIFDT < dateadd (day, -5,GETDATE())
AND N.DATE1 < dateadd (day, -5,GETDATE())
and S.SOPTYPE in (2,3)
and S.VOIDSTTS = 0
OR E.[Must Ship By] = '1900-01-01 00:00:00.000'
OR E.[Must Ship By] IS NULL

Hopefully my description of what I am trying to accomplish is sufficient for someone to point me in the right direction.

Thank you,

Kirk

*This post is locked for comments

  • 26P2ER Profile Picture
    1,775 on at
    RE: SQL Code to Identify Inactive Orders

    Kirk - I missed seeing your answer before posting mine.

  • KirkLivermont Profile Picture
    5,985 on at
    RE: SQL Code to Identify Inactive Orders

    Ven,

    Thank you for your response.

    Kirk

  • Verified answer
    26P2ER Profile Picture
    1,775 on at
    RE: SQL Code to Identify Inactive Orders

    Hello Kirk:

    You are on the right track, the only change I would propose is the below

    where s.MODIFDT < dateadd (day, -5,GETDATE())
    AND N.DATE1 < dateadd (day, -5,GETDATE())
    and S.SOPTYPE in (2,3)
    and S.VOIDSTTS = 0 

    and (
    OR E.[Must Ship By] = '1900-01-01 00:00:00.000'
    OR E.[Must Ship By] IS NULL)

    Hope this helps

  • Verified answer
    KirkLivermont Profile Picture
    5,985 on at
    RE: SQL Code to Identify Inactive Orders

    A little lame of me but I think I just needed to add an extra and as well as put the or section in parentheses.

    Here is the working code for anyone that might want to make something similar.

    select

    S.sopnumbe,

    S.CUSTNMBR,

    S.DOCDATE,

    S.BACHNUMB,

    S.MODIFDT,

    N.TXTFIELD,

    N.DATE1,

    E.[SOP Number],

    E.[Must Ship By]

    from SOP10100 S

    inner join SY03900 N

    ON S.NOTEINDX = N.NOTEINDX

    left outer join JR_EXT_TKR1 E

    ON S.SOPNUMBE = E.[SOP Number]

    where s.MODIFDT < dateadd (day, -5,GETDATE())

    AND N.DATE1 < dateadd (day, -5,GETDATE())

    and S.SOPTYPE in (2,3)

    and S.VOIDSTTS = 0

    and (E.[Must Ship By] = '1900-01-01 00:00:00.000'

    OR E.[Must Ship By] IS NULL)

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Almas Mahfooz Profile Picture

Almas Mahfooz 3 User Group Leader

Featured topics

Product updates

Dynamics 365 release plans