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

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Verified answer
    KirkLivermont Profile Picture
    5,985 on at

    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)

  • Verified answer
    26P2ER Profile Picture
    1,775 on at

    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

  • KirkLivermont Profile Picture
    5,985 on at

    Ven,

    Thank you for your response.

    Kirk

  • 26P2ER Profile Picture
    1,775 on at

    Kirk - I missed seeing your answer before posting mine.

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 > 🔒一 Microsoft Dynamics GP (Archived)

#1
mtabor Profile Picture

mtabor 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans