# SQL query to get GL transaction in AX2012R2/3 with main account and department

**URL:** <https://www.dynamicsuser.net/t/sql-query-to-get-gl-transaction-in-ax2012r2-3-with-main-account-and-department/54806>\
**Category:** User Forum\
**Created:** [September 10, 2014, 12:06pm UTC](https://www.dynamicsuser.net/t/sql-query-to-get-gl-transaction-in-ax2012r2-3-with-main-account-and-department/54806 "2014-09-10T12:06:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![koong007](https://avatars.discourse-cdn.com/v4/letter/k/cab0a1/32.png) [@koong007](https://www.dynamicsuser.net/u/koong007)\
**Post date:** [September 10, 2014, 12:06pm UTC](https://www.dynamicsuser.net/t/sql-query-to-get-gl-transaction-in-ax2012r2-3-with-main-account-and-department/54806/1 "2014-09-10T12:06:22Z")

</div>

Hi,

I would like to share this SQL query script, this use to get the GL transacitons with main account and department,

select com.NAME, gje.ACCOUNTINGDATE,m.MAINACCOUNTID, gjae.ACCOUNTINGCURRENCYAMOUNT, dc.DISPLAYVALUE, isnull(dcv.DISPLAYVALUE,’’) as ‘Departmnet’

from GENERALJOURNALENTRY gje

inner join GENERALJOURNALACCOUNTENTRY gjae on gje.RECID = gjae.GENERALJOURNALENTRY

inner join DIMENSIONATTRIBUTEVALUECOMBINATION dc on gjae.LEDGERDIMENSION = dc.RECID

inner join MAINACCOUNT m on dc.MAINACCOUNT = m.RECID

inner join ledger com on gje.LEDGER = com.RECID --ledger table is companyid

left outer join DIMENSIONATTRIBUTELEVELVALUEVIEW dcv on dc.recid= dcv.VALUECOMBINATIONRECID and DIMENSIONATTRIBUTE = ‘5637146076’

–get dimensionattribute value from dimensionattribute able for department

Koong
