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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

AA SQL Query to Pull Historical Data

(0) ShareShare
ReportReport
Posted on by 211

I am trying to create a SQL Query which will pull Analytical Accounting information along with GL information for closed years.  My query is shown below:

SELECT
A.JRNENTRY ,
Z.ORDOCNUM,
H.ACTNUMST ,
B.aaVendID,
Z.REFRENCE,
G.ACTDESCR ,
A.aaTRXType ,
aaGLTRXSource ,
aaTRXSource ,
GLPOSTDT ,
--B.DEBITAMT AS TotalDebit ,
--B.CRDTAMNT AS TotalCredit ,
C.DEBITAMT AS aaDebit ,
C.CRDTAMNT AS aaCredit ,
aaTrxDim ,
aaTrxDimDescr ,
aaTrxDimDescr2 ,
aaTrxDimCode ,
aaTrxDimCodeDescr ,
aaTrxDimCodeDescr2

FROM [AAG40000] AS A
LEFT OUTER JOIN [AAG40001] AS B ON A.[aaGLHdrID] = B.[aaGLHdrID]
LEFT OUTER JOIN [AAG40002] AS C ON B.[aaGLHdrID] = C.[aaGLHdrID]
AND B.[aaGLDistID] = C.[aaGLDistID]
INNER JOIN [AAG40003] AS D ON C.[aaGLAssignID] = D.[aaGLAssignID]
AND C.[aaGLDistID] = D.[aaGLDistID]
AND C.[aaGLHdrID] = D.[aaGLHdrID]
INNER JOIN GL30000 AS Z ON A.JRNENTRY = Z.JRNENTRY AND A.YEAR1 = Z.HSTYEAR

INNER JOIN [AAG00401] AS E ON D.[aaTrxDimID] = E.[aaTrxDimID]
AND D.[aaTrxCodeID] = E.[aaTrxDimCodeID]
INNER JOIN [AAG00400] AS F ON E.[aaTrxDimID] = F.[aaTrxDimID]
LEFT OUTER JOIN dbo.GL00100 AS G ON B.ACTINDX = G.ACTINDX
LEFT OUTER JOIN dbo.GL00105 AS H ON G.ACTINDX = H.ACTINDX

WHERE Z.ACTINDX = B.ACTINDX AND
aaTrxDim = 'BRANDEXP'

However, this query is returning duplicated rows and the issue appears to be the link between the AAG40000 table and the GL30000 table because when I remove the latter table the query is fine.  Can anyone let me know what modification I need to make ?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mike Bufano Profile Picture
    1,484 on at

    I haven't looked at this closely but I am not surprised you are returning duplicate records.  This is because you are only joining GL30000 on the JRNENTRY and the YEAR.  

    You should also be joining the ACTINDX.  

    I would suggest as a possibility INNER JOIN GL30000 AS Z ON A.JRNENTRY = Z.JRNENTRY AND A.YEAR1 = Z.HSTYEAR and b.actindx = z.actindx

  • TracySam Profile Picture
    211 on at

    I tried that but I am still getting duplications

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Shravan Attelli Profile Picture

Shravan Attelli 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans