Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

SQL query help

Posted on by Microsoft Employee

I'm looking for a SQL query that will pull sales for a year with GL distribution AND the ship to state.  Does this query look ok - I'm not sure about the joins

select
'xxx' COMPANY,
OPENYEAR Trx_Year,
TRXDATE Trx_Date,
JRNENTRY Journal_Entry,
ORTRXSRC Originating_TRX_Source,
ORMSTRID Originating_Master_ID,
ORMSTRNM Originating_Master_Name,
ORDOCNUM Originating_Doc_Number,
DEBITAMT Debit_Amount,
CRDTAMNT Credit_Amount,
ACTNUMST Account_Number,
ACTDESCR Account_Description,
ACCATDSC Account_Category,
ORPSTDDT originating_post_date,
ORIGNUMB SOPORIGNUMB,
STATE

from
(select ACTINDX, OPENYEAR, TRXDATE, JRNENTRY, ORTRXSRC, ORPSTDDT,
ORDOCNUM, ORMSTRID, ORMSTRNM, DEBITAMT, CRDTAMNT
from GL20000
where (SERIES = '3') and OPENYEAR = '2015') GL

inner join GL00105 GM
on GL.ACTINDX = GM.ACTINDX
inner join GL00100 GA
on GL.ACTINDX = GA.ACTINDX
inner join GL00102 C
on GA.ACCATNUM= C.ACCATNUM
inner join SOP30200  S
on GL.ORDOCNUM= S.ORIGNUMB

go

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SQL query help

    OMG - this is awesome!   I know my joins were messing me up.

    Thank you so very much Leslie!  My only other tweak was to add SOPTYPE = '3' because I just needed to get invoices.  

  • Verified answer
    L Vail Profile Picture
    L Vail 65,271 on at
    RE: SQL query help

    Hi,

    I think you might want something like this:

    SELECT GL20000.OPENYEAR AS Trx_Year

    ,GL20000.TRXDATE AS Trx_Date

    ,GL20000.JRNENTRY AS Journal_Entry

    ,GL20000.ORTRXSRC AS Originating_TRX_Source

    ,GL20000.ORMSTRID AS Originating_Master_ID

    ,GL20000.ORMSTRNM AS Originating_Master_Name

    ,GL20000.ORDOCNUM AS Originating_Doc_Number

    ,GL20000.DEBITAMT AS Debit_Amount

    ,GL20000.CRDTAMNT AS Credit_Amount

    ,GL00105.ACTNUMST AS Account_Number

    ,GL00100.ACTDESCR AS Account_Description

    ,GL00102.ACCATDSC AS Account_Category

    ,GL20000.ORPSTDDT AS originating_post_date

    ,SOP30200.sopnumbe AS SOP_Number

    ,SOP30200.SOPTYPE AS SOP_Type

    ,SOP30200.STATE

    FROM GL20000

    INNER JOIN SOP30200 ON GL20000.ORDOCNUM = SOP30200.SOPNUMBE

    INNER JOIN GL00100 ON GL20000.ACTINDX = GL00100.ACTINDX

    INNER JOIN GL00105 ON GL20000.ACTINDX = GL00105.ACTINDX

    INNER JOIN GL00102 ON GL00100.ACCATNUM = GL00102.ACCATNUM

    WHERE (GL20000.SERIES = '3')

    AND (GL20000.OPENYEAR = '2015')

    Kind regards,

    Leslie

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!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans