SQL Query fun: Dynamics AX 2012 Main Account – Financial dimension read
October 1, 2019 1 Comment
Hi,
This is new blog on knowledge share, today just got chance to work with SQL queries; i was just exploring the dimension extract for one of our customer, i produce this sql query which show main account and financial dimensions associated with main account; i though it is worth to share with AX community also.
-- This script is designed to show the values in columns for better read -- Deleting if tmp table already exists Begin drop table #MainAccountDimensionTmp End -- creating new Tmp table. Begin CREATE TABLE #MainAccountDimensionTmp ( MainAccount nvarchar(100), DisplayValue nvarchar(100), Name nvarchar(100) ) End -- selecting main accounts and all financial dimensions and storing into tmp table Begin Insert into #MainAccountDimensionTmp (Name, DisplayValue, MainAccount) select ddv.NAME, ddv.DISPLAYVALUE, MAINACCOUNT.MAINACCOUNTID from MainAccountLegalEntity as MALE join MAINACCOUNT on MAINACCOUNT.RECID = MALE.MAINACCOUNT join DEFAULTDIMENSIONVIEW as ddv on MALE.DEFAULTDIMENSION = ddv.DEFAULTDIMENSION --where MAINACCOUNTid = 'test01' end -- reading again from tmp table in way that values are showin in column. -- please add as many dimesions as you want, like i have added 4 dimensins below. Select MainAccount, MAX( Case Name When 'Department' then DISPLAYVALUE ELSE '' END ) AS 'Department', MAX( Case Name when 'ICP' then DisplayValue ELSE '' END ) AS 'ICP', MAX( Case Name when 'MISC' then DisplayValue ELSE '' END ) AS 'MISC', MAX( Case Name when 'Expense_Class' then DisplayValue ELSE '' END ) AS 'Expense Class' from #MainAccountDimensionTmp Group by MainAccount --select * from DEFAULTDIMENSIONVIEW
Query results: