Hi, <Posted by K Day replied on 08-27-2010 4:18 PM >
Thanks for sharing your queries, they are pretty helpful.
I modified your query (see code below) because single link to aaTRxDimCodeId was duplicating data. In my scenario there are records with the same aaTRxDimCodeId, so I add a link to field aaTrxDimId together with aaTrxDimCodeID. so far is not showing duplicates.
I have a question, how come some aaTRxDimCodeId are null? why they exist in AAGxxx.. Tables
SELECT TOP (100) PERCENT g.aaTrxDim, h.aaTrxDimCode, a.aaGLHdrID, a.JRNENTRY, a.RCTRXSEQ, a.YEAR1, a.aaTRXType, a.aaGLTRXSource,
a.aaTRXSource, a.GLPOSTDT, a.DEX_ROW_ID, d.ACTDESCR, e.ACTNUMST, 'AAG30001 -->' AS Expr1, b.aaGLHdrID AS Expr2, b.aaGLDistID,
b.INTERID, b.CorrespondingUnit, b.ACTINDX, b.ACCTTYPE, b.aaBrowseType, b.DECPLACS, b.DEBITAMT, b.CRDTAMNT, b.ORDBTAMT, b.ORCRDAMT,
b.CURNCYID, b.CURRNIDX, b.RATETPID, b.EXGTBLID, b.XCHGRATE, b.EXCHDATE, b.TIME1, b.RTCLCMTD, b.DENXRATE, b.MCTRXSTT, b.SEQNUMBR,
b.aaCustID, b.aaVendID, b.aaSiteID, b.aaItemID, b.aaCopyStatus, b.aaChangeDate, b.aaChangeTime, b.DEX_ROW_ID AS Expr3,
'AAG30002 -->' AS Expr4, c.aaGLHdrID AS Expr5, c.aaGLDistID AS Expr6, c.aaGLAssignID, c.DEBITAMT AS Expr7, c.CRDTAMNT AS Expr8,
c.ORDBTAMT AS Expr9, c.ORCRDAMT AS Expr10, c.aaAssignedPercent, c.DistRef, c.NOTEINDX, c.DEX_ROW_ID AS Expr11, f.aaGLHdrID AS Expr12,
f.aaGLDistID AS Expr13, f.aaGLAssignID AS Expr14, f.aaTrxDimID, f.aaTrxCodeID, f.DEX_ROW_ID AS Expr15, e.ACTNUMBR_3,
(SELECT TOP (1) ORDOCNUM
FROM dbo.GL20000
WHERE (JRNENTRY = a.JRNENTRY) AND (TRXSORCE = a.aaGLTRXSource)) AS DocRef,
(SELECT TOP (1) ORMSTRNM
FROM dbo.GL20000 AS GL20000_1
WHERE (JRNENTRY = a.JRNENTRY) AND (TRXSORCE = a.aaGLTRXSource)) AS Customer
FROM dbo.AAG00401 AS h RIGHT OUTER JOIN
dbo.AAG30003 AS f ON h.aaTrxDimID = f.aaTrxDimID AND h.aaTrxDimCodeID = f.aaTrxCodeID RIGHT OUTER JOIN
dbo.AAG30000 AS a LEFT OUTER JOIN
dbo.AAG30001 AS b ON a.aaGLHdrID = b.aaGLHdrID LEFT OUTER JOIN
dbo.AAG30002 AS c ON b.aaGLHdrID = c.aaGLHdrID AND b.aaGLDistID = c.aaGLDistID LEFT OUTER JOIN
dbo.GL00100 AS d ON d.ACTINDX = b.ACTINDX LEFT OUTER JOIN
dbo.GL00105 AS e ON e.ACTINDX = b.ACTINDX ON f.aaGLHdrID = c.aaGLHdrID AND f.aaGLDistID = c.aaGLDistID AND
f.aaGLAssignID = c.aaGLAssignID LEFT OUTER JOIN
dbo.AAG00400 AS g ON g.aaTrxDimID = f.aaTrxDimID
ORDER BY a.JRNENTRY