Error 3296: Join expression not supported in MS Access Query with multiple JOIN - sql

I'm using Access 2003 and doing a make table query.
The idea is, I have multiple tables containing all kinds of info on a list of funds, and I am trying to combined them. All tables have FundID as one of the fields, and this is the field we use to identify each individual fund. There's a table for a field MER, which are updated from time to time. So we have to apply the MER values for its applicable periods. Here's my SQL code:
SELECT
[Fund Mapping].FundID,
[Fund Mapping].FundName,
[MarketValues].DateLookup,
[MarketValues].[SumOfCurrentAmt]/100 AS [MV By Fund],
[Fund Prices # Month End].Price,
IIf([MarketValues].DateLookup<"200908",[MER (08 to Jul 09)].MER,
IIf([MarketValues].DateLookup<"200911",[MER (Aug 09 to Oct 09)].MER,
IIf([MarketValues].DateLookup<"201008",[MER (Nov 09 to Jul 10)].MER,
IIf([MarketValues].DateLookup<"201106",[MER (Aug 10 to May 11)].MER,[MER (Jun 11 to present)].MER)
)
)
) AS MER
INTO [Fund Data]
FROM [Fund Mapping],
[MER (08 to Jul 09)] RIGHT JOIN
([MER (Aug 09 to Oct 09)] RIGHT JOIN
([MER (Nov 09 to Jul 10)] RIGHT JOIN
([MER (Aug 10 to May 11)] RIGHT JOIN
([MER (Jun 11 to present)] RIGHT JOIN
([MarketValues] INNER JOIN [Fund Prices # Month End]
ON ([MarketValues].DateLookup = [Fund Prices # Month End].DateLookup)
AND ([MarketValues].FundID = [Fund Prices # Month End].[Fund ID]))
ON [MER (Jun 11 to present)].FundID = [MarketValues].FundID)
ON [MER (Aug 10 to May 11)].FundID = [MarketValues].FundID)
ON [MER (Nov 09 to Jul 10)].FundID = [MarketValues].FundID)
ON [MER (Aug 09 to Oct 09)].FundID = [MarketValues].FundID)
ON [MER (08 to Jul 09)].FundID = [MarketValues].FundID
GROUP BY
[Fund Mapping].FundID,
[Fund Mapping].FundName,
[MarketValues ].DateLookup,
[SumOfCurrentAmt]/100,
[Fund Prices # Month End].Price,
IIf([MarketValues].DateLookup<"200908",[MER (08 to Jul 09)].MER,
IIf([MarketValues].DateLookup<"200911",[MER (Aug 09 to Oct 09)].MER,
IIf([MarketValues].DateLookup<"201008",[MER (Nov 09 to Jul 10)].MER,
IIf([MarketValues].DateLookup<"201106",[MER (Aug 10 to May 11)].MER,[MER (Jun 11 to present)].MER)
)
)
)
ORDER BY
[Fund Mapping].FundID,
[MarketValues].DateLookup;
DateLookup are strings with the format of YYYYMM. The reason why I am using RIGHT JOIN instead of INNER JOIN is because there can be new funds added, so the earlier MER tables will not have all the FundIDs. The "MarketValues INNER JOIN Fund Prices # Month End" table should be the base of this whole thing - it has all the funds, and nothing should be dropped from this.
When I tried to save the query, it gave me an error message saying JOIN expression not supported. I don't know what's wrong or how I can fix it.
Help please? Thanks in advance!
========== UPDATE #1
I manually added each of the join properties and the entire query from scratch in design view. It gave me pretty much the same code as above, but allowed me to save (the code above gives me an error whenever I try to save).
But when I tried to run the query, it gives me an error message that says: "The SQL statement could not be executed because it contains ambiguous outer joins. To force one of the joins to be performed first, create a separate query that performs the first join and then include that query in your SQL Statement."
Is there no other way around this?
========== UPDATE #2
So I digged a bit further, and was able to resolve the problem and have the query run properly.
Turns out all I had to do was to JOIN [Fund Mapping] table together with all the other tables! Ie, all the tables I am selecting from are joined together.
Just thought I should give an update in case anyone else encounters the same problem.
Thank you for helping out!

I think the problem is mixing 'old style' cross join with infix join style e.g. consider this simplified example that generates the same error:
SELECT *
FROM T1, T2 RIGHT JOIN T3 ON T2.c = T3.c;
One simple fix to the above is to perform the RIGHT JOIN in another scope e.g. in a derived:
SELECT *
FROM T1, (
SELECT T2.*, T3.c2
FROM T2 RIGHT JOIN T3 ON T2.c = T3.c
) AS DT1;

See Update #2 for solution to this problem.

Related

Query not picking up correct end date of staff

I have got MS Access query (in SQL view) that is not recognising the last bit -
AND ((dbo_EMTER.TER_DATE) Is Null Or (dbo_EMTER.TER_DATE)>"12/31/2018"));
That column is basically looking at staff who do not have an end date or have a terminated date in the system after 31st Dec 2018, however my query is picking up records with no end date as well as records prior to 31st Dec 2018.
My full query is below (Looking at sick leave off staff over the year), could someone please let me know what is happening?
SELECT dbo_EMDET.DET_NUMBER, dbo_EMDET.DET_G1_NAME1,
dbo_EMDET.DET_SURNAME,
dbo_EMDET.DET_DATE_JND, dbo_EMPOS.POS_PDT_HRS, dbo_EMPOS.POS_AV_HR_WK,
dbo_EMPOS.POS_DAYS_WK, [POS_AV_HR_WK]/[POS_DAYS_WK] AS [average hours in
day], [LVE_HOUR_TKN]/[average hours in day] AS [average day taken],
dbo_EMLVE.LVE_HOUR_TKN, dbo_EMLVE.LVE_DAY_TAKE, dbo_EMLVE.LVE_START,
dbo_EMLVE.LVE_END, dbo_EMLVE.LVE_TYPE_CD, dbo_EMPAY.DET_NUMBER,
dbo_EMPAY.PYD_COMPANY, dbo_EMPOS.POS_START, dbo_EMPOS.POS_END,
dbo_EMPOS.POS_L0_CD, dbo_EMPOS.POS_L1_CD, dbo_EMPOS.POS_L2_CD,
dbo_EMPOS.POS_L3_CD, dbo_EMPOS.POS_L4_CD, dbo_EMPOS.POS_L5_CD,
dbo_EMPOS.POS_L6_CD, dbo_EMPOS.POS_ALT_CD1, dbo_EMPOS.POS_ALT_CD2,
dbo_EMPOS.POS_STATUS, [Translation Table].[Code Description],
dbo_EMPOS.POS_PDT_STAT, dbo_EMTER.TER_DATE,
IIf(Left([POS_L5_CD],1)="G","Core","Other") AS [Staff Grouping]
FROM ((((dbo_EMDET LEFT JOIN dbo_EMLVE ON dbo_EMDET.DET_NUMBER =
dbo_EMLVE.DET_NUMBER) LEFT JOIN dbo_EMPAY ON dbo_EMDET.DET_NUMBER =
dbo_EMPAY.DET_NUMBER) INNER JOIN [max position 2] ON dbo_EMDET.DET_NUMBER =
[max position 2].DET_NUMBER) INNER JOIN (dbo_EMPOS LEFT JOIN [Translation
Table] ON dbo_EMPOS.POS_STATUS = [Translation Table].Name) ON ([max position
2].DET_NUMBER = dbo_EMPOS.DET_NUMBER) AND ([max position 2].MaxOfPOS_START =
dbo_EMPOS.POS_START)) LEFT JOIN dbo_EMTER ON dbo_EMDET.DET_NUMBER =
dbo_EMTER.DET_NUMBER
WHERE (((dbo_EMLVE.LVE_START)>"01/01/2018" And (dbo_EMLVE.LVE_START)
<"12/31/2018") AND ((dbo_EMLVE.LVE_TYPE_CD)="SIC" Or
(dbo_EMLVE.LVE_TYPE_CD)="DOM" Or (dbo_EMLVE.LVE_TYPE_CD)="ACC" Or
(dbo_EMLVE.LVE_TYPE_CD)="WCME" Or (dbo_EMLVE.LVE_TYPE_CD)="WCMN" Or
(dbo_EMLVE.LVE_TYPE_CD)="WCM2" Or (dbo_EMLVE.LVE_TYPE_CD)="WCM" Or
(dbo_EMLVE.LVE_TYPE_CD)="SLWP" Or (dbo_EMLVE.LVE_TYPE_CD)="SPEC" Or
(dbo_EMLVE.LVE_TYPE_CD)="SWOP") AND ((dbo_EMPAY.PYD_COMPANY)="PS" Or
(dbo_EMPAY.PYD_COMPANY)="PSC") AND ((dbo_EMPOS.POS_L3_CD)<>"CGS") AND
((dbo_EMPOS.POS_STATUS)<>"C") AND ((dbo_EMTER.TER_DATE) Is Null Or
(dbo_EMTER.TER_DATE)>"12/31/2018"));
If you need to know any other further please to assist, please let me know.
Thanks team :)
Probably, your "dates" are not date values but text, thus not to be filtered as expected.
This happens if you use DateTime2 and the old SQL Server ODBC driver. So, either use data type DateTime or use the SQL Server Native Client 11.0 or newer.

T-SQL Query will not return 0 value for a Sum

I have a query where I'm calculating Days of Therapy for medications. I want to have 0 values to show for months that have no data. Currently the query returns no record if the Sum is 0. Can't seem to figure this out. See the Query Below:
If I were to comment out identifiers related to the DOT_ALL table along with the Where Clause I get 60 rows, 1 for each month for the past 5 years. However, otherwise i get only 57 for the drug in the Where Clause since there are not DOTs for Aug 2016, April 2016 and Jan 2015.
Thanks in advance.
----------------------------------------------------------------------------
SELECT
AMS.[Medication Name]
, SUM(AMS.DOT) AS DOT
, PD.[Patient Days]
, PD.[Month_Name]
, PD.[Fiscal_Month]
, PD.[Accounting_Year]
, PD.[Year]
FROM
DW_PROD.dbo.Patient_Days_By_Month PD
Left JOIN [DW_PROD].[dbo].[DOTS_All] AMS ON (PD.Month_Name = AMS.Month AND PD.Year = AMS.Year)
WHERE
[Medication Name] = 'CEFUROXIME'
GROUP BY
AMS.[Medication Name]
, PD.[Patient Days]
, PD.[Month_Name]
, PD.[Fiscal_Month]
, PD.[Accounting_Year]
, PD.[Year]
ORDER BY
ACCOUNTING_YEAR
,FISCAL_MONTH
This may be the cheapest solution, under the assumption that Patient_Days_By_Month is already some kind of calendar.
SELECT
'CEFUROXIME' AS [Medication Name],
SUM(AMS.DOT) AS DOT,
PD.[Patient Days],
PD.[Month_Name],
PD.[Fiscal_Month],
PD.[Accounting_Year],
PD.[Year]
FROM DW_PROD.dbo.Patient_Days_By_Month PD
LEFT JOIN [DW_PROD].[dbo].[DOTS_All] AMS
ON PD.Month_Name = AMS.Month
AND PD.Year = AMS.Year
AND [Medication Name] = 'CEFUROXIME'
GROUP BY
PD.[Patient Days],
PD.[Month_Name],
PD.[Fiscal_Month],
PD.[Accounting_Year],
PD.[Year]
ORDER BY
PD.ACCOUNTING_YEAR,
PD.FISCAL_MONTH
JOIN conditions do not need to refer to columns in other tables, they can as well contain constants.
The medication name was originally restricted in the WHERE clause - that eliminated all non-cefuroxime records from the resultset.

SQL Left Outer Join on Subquery

I am attempting to build a query that contains a left join subquery - based on the principles I learned in a previous question - that should pull similar data sets from two different tables. The goal is to compare volume data by account || platform to ensure that the stored procedure that creates one table from another is doing so correctly.
The idea is this:
Account || Product || T1Vol || T2Vol
abc AT 10 10
def RT 20 25
ghi OB 30
So with this example, the idea is to pull all accounts and products from T1 (the table the procedure acts on) and any accounts and products from T2 (the newly created table) where there is a match (so, Left Join on T1 = T2). (Ideally, everything will match perfectly, with no variance in T1 vs T2 vol and no nulls in T2 volume).
I wrote the following the query to accomplish this but its not quite working. The current error I get is not a GROUP BY expression - which I don't think is the real issue. I have been searching and with iterations to no avail.
The query is below. (To keep with the example, T1 = OpStats and T2 = RegSplits. Any help is much appreciated.
SELECT DTA.trading_code Account, OpStats.product_dwkey Platform, SUM(OpStats.risk_amount_adj)/1000000 OpStatsVol, RegSplits.Volume RegSplitsVol
FROM fact_trade_presplit_rollup OpStats
INNER JOIN dim_trading_accounts DTA ON OpStats.trading_dwkey=DTA.trading_dwkey
LEFT OUTER JOIN
( SELECT b.trading_Code Account, a.product_dwkey Platform, SUM(a.risk_amount_adj)/1000000 Volume
FROM fact_trade_rollup a
INNER JOIN dim_trading_accounts b on a.trading_dwkey=b.trading_dwkey
WHERE a.account_type IN('Customer','Taker')
AND a.date_key>='01-JAN-16'
AND a.date_key<='31-MAR-16'
AND a.daily_db_metric NOT IN ('Manual Treasury Volume ($B)', 'Manual Volume ($B)', 'HSBC-WL POMS (Internal) Volume ($B)','JPMC-WL Order Book (Internal) Volume ($B)')
AND (a.product_dwkey IN('RT','HWL') AND a.source_name<>'STP')
GROUP BY b.trading_code, a.product_dwkey ) RegSplits
ON (DTA.trading_code = RegSplits.Account) /* is it because I am trying to join DTA to the subquery */
WHERE OpStats.account_type IN('Customer','Taker')
AND OpStats.date_key>='01-JAN-16'
AND OpStats.date_key<='31-MAR-16'
AND OpStats.daily_db_metric NOT IN ('Manual Treasury Volume ($B)', 'Manual Volume ($B)', 'HSBC-WL POMS (Internal) Volume ($B)','JPMC-WL Order Book (Internal) Volume ($B)')
AND (OpStats.product_dwkey IN('RT','HWL') AND OpStats.source_name<>'STP')
GROUP BY DTA.trading_code, OpStats.product_dwkey;
The "Not group by expression" error is very easy to check.
Just compare SELECT expressions with GROUP BY expressions:
SELECT DTA.trading_code Account,
OpStats.product_dwkey Platform,
SUM(OpStats.risk_amount_adj)/1000000 OpStatsVol,
RegSplits.Volume RegSplitsVol
FROM ......
......
GROUP BY DTA.trading_code,
OpStats.product_dwkey;
There are two elements in SELECT that are not in GROUP BY:
SUM(OpStats.risk_amount_adj)/1000000 OpStatsVol
RegSplits.Volume RegSplitsVol
The number 1 is OK - it's an aggregate function, it cannot be in GROUP BY.
The number 2 caused this error - it's not an aggregate function, and it is not listed in GROUP BY clause.

Subtract. SQL daily value (today value - yesterday value)

Friends,
I have a database, where i keep all users traffic. It updates each day.
I want to count a traffic per day. It means: traffic today - traffic yesterday?
There are three tables (down, up, remoteid). There are the results:
select rem.remoteid, down.mazgas, down.portas, down.down, up.up, down.date
from dbo.remoteid as rem
inner join dbo.down as down on down.mazgas=rem.mazgas and down.portas = rem.portas
inner join dbo.up as up on up.mazgas=down.mazgas and up.portas = down.portas
where down.mazgas=up.mazgas and down.portas=up.portas and down.date= up.date
result
remoteid mazgas portas down up date
10156529 10.199.100.27 gpon-onu_1/12/5:1 2678.0 69963.9 2014-06-01
10156529 10.199.100.27 gpon-onu_1/12/5:1 2643.8 68912.3 2014-05-31
29546232 10.203.100.1 gpon-onu_1/16/1:4 927.8 39273.6 2014-06-01
29546232 10.203.100.1 gpon-onu_1/16/1:4 923.1 39126.7 2014-05-31
I would like to get an answer:
remoteid, mazgas, portas, down, up where down = (down(today) - down(yesterday)) and up= (up(today) - up(yesterday))
Thank You a lot.
Since you did not specify the RDBMS you are using I will try to use basic SQL. Something like this would give you the desired results:
SELECT
r.remoteid,
r.mazgas,
r.portas,
COALESCE(d2.down,0)-COALESCE(d1.down,0) AS down,
COALESCE(u2.up ,0)-COALESCE(u1.up ,0) AS up,
d2.date
FROM dbo.remoteid AS r
JOIN dbo.down AS d2 ON d2.mazgas=r.mazgas AND d2.portas=r.portas
LEFT JOIN dbo.up AS u2 ON u2.mazgas=r.mazgas AND u2.portas=r.portas AND u2.date=d2.date
LEFT JOIN dbo.down AS d1 ON d1.mazgas=r.mazgas AND d1.portas=r.portas AND d1.date=(
SELECT MAX(date)
FROM dbo.down
WHERE mazgas=r.mazgas AND portas=r.portas AND date<d2.date)
LEFT JOIN dbo.up AS u1 ON u1.mazgas=r.mazgas AND u1.portas=r.portas AND u1.date=(
SELECT MAX(date)
FROM dbo.up
WHERE mazgas=r.mazgas AND portas=r.portas AND date<u2.date)
Things to consider:
COALESCE is not supported on all RDBMS. But there should be something to substitute it with (IFNULL or IF or IIF). As a last resort, you can fallback on a CASE WHEN which is supported by most. But the COALESCE or equivalent is important. You do have to consider NULLs in this join. You are joining download, uploads on 2 different dates... ignoring NULLs is asking for trouble.
I opted for referring to the remoteid table for mazgas and portas. This seems more solid than using the down table, as I suppose the remoteid master record should always exist, and does not depend on dates.
This will not give you the difference with yesterday's value, but the difference with the last date that has values (same mazgas and portas). If all days have values, then the result is the same.
What you want can be done with some date algebra, like this simple -1 syntax:
SELECT
r.remoteid,
r.mazgas,
r.portas,
COALESCE(d2.down,0)-COALESCE(d1.down,0) AS down,
COALESCE(u2.up ,0)-COALESCE(u1.up ,0) AS up,
d2.date
FROM dbo.remoteid AS r
JOIN dbo.down AS d2 ON d2.mazgas=r.mazgas AND d2.portas=r.portas
LEFT JOIN dbo.up AS u2 ON u2.mazgas=r.mazgas AND u2.portas=r.portas AND u2.date=d2.date
LEFT JOIN dbo.down AS d1 ON d1.mazgas=r.mazgas AND d1.portas=r.portas AND d1.date=d2.date-1
LEFT JOIN dbo.up AS u1 ON u1.mazgas=r.mazgas AND u1.portas=r.portas AND u1.date=u2.date-1
... but different RDBMS may handle date algebra in other ways (they all have some function to add, subtract days though).
As far as efficiency goes... well you have better have indexes on mazgas, portas, date on both the down table and the up table ;)

Optimizing An Oracle Query with Sub-Queries Using Identical Tables From the Parent

I'm working on a MVC 3 project where some of the reports will generate the SQL queries in code then executes them on an Oracle 10g database. Also, I understand SQL injection attacks, and all the values are coming from drop down lists, not text inputs, so this is not an issue. My generated queries "work", but they are extremely slow. Here is a quick run down on how the report works:
User selected a general ledger account and other filters.
User selected a time period (a fiscal year, a quarter or a specific month).
User runs report.
The report shows the general ledger account (or accounts if the select to show all accounts) and the values spent for each month along with a total for that account. The output from the query will look like this:
Account Number and Name | Month 1 | Month 2 | etc | Total
Month 1, Month 2, etc are dynamically added in while the SQL code is being generated, so depending on what the user selects, it may, or may not, be returned in the result set. What can I do to make this query faster? When I ran this query yesterday for the entire fiscal year (and only 1 account), it took 10mins for it to complete. I don't feel this is acceptable performance, and would like to make it faster. Keep in mind, I can only make changes to the query itself, not the database, so indexing is not going to happen (the DBAs keep everything locked down). The query is below. Thanks for any input you all can provide on this.
SELECT gl.gen_led_acct_nbr, gl.gen_led_acct_scr_nm, bu.bus_unit_txt, gl.gen_led_acct_typ_nm,
(SELECT SUM(fct.pd_txn_amt) Jun2012
FROM Maintable fct
JOIN Dimtable1 gl1 ON fct.gen_led_acct_key = gl1.gen_led_acct_key
JOIN Dimtable2 bu1 ON fct.bus_unit_key = bu1.bus_unit_key
JOIN Dimtable3 cc1 ON fct.cst_ctr_key = cc1.cst_ctr_key
JOIN Dimtable4 oc1 ON fct.cst_ctr_own_org_key = oc1.org_cd_key
JOIN Dimtable5 dt1 ON fct.chk_dt_key = dt1.dt_key
WHERE gl1.gen_led_acct_nbr = gl.gen_led_acct_nbr
AND bu1.bus_unit_txt = bu.bus_unit_txt
AND dt1.fscl_mo_nbr = 1
AND dt1.fscl_yr_nbr = 2012
GROUP BY gl1.gen_led_acct_nbr, gl1.gen_led_acct_scr_nm, bu1.bus_unit_txt) Jun2012,
(SELECT SUM(fct.pd_txn_amt) Jun2012
FROM Maintable fct
JOIN Dimtable1 gl2 ON fct.gen_led_acct_key = gl2.gen_led_acct_key
JOIN Dimtable2 bu2 ON fct.bus_unit_key = bu2.bus_unit_key
JOIN Dimtable3 cc2 ON fct.cst_ctr_key = cc2.cst_ctr_key
JOIN Dimtable4 oc2 ON fct.cst_ctr_own_org_key = oc2.org_cd_key
JOIN Dimtable5 dt2 ON fct.chk_dt_key = dt2.dt_key
WHERE gl2.gen_led_acct_nbr = gl.gen_led_acct_nbr
AND bu2.bus_unit_txt = bu.bus_unit_txt
AND dt2.fscl_mo_nbr = 2
AND dt2.fscl_yr_nbr = 2012
GROUP BY gl2.gen_led_acct_nbr, gl2.gen_led_acct_scr_nm, bu2.bus_unit_txt) Jul2012,
(etc...)
--The sub queries above can be repeated up to an indefinite amount of times (maybe 20+), but with a different fscl_mo_nbr (and possibly fscl_yr_nbr as well)
FROM Maintable fct
JOIN Dimtable1 gl ON fct.gen_led_acct_key = gl.gen_led_acct_key
JOIN Dimtable2 bu ON fct.bus_unit_key = bu.bus_unit_key
JOIN Dimtable3 cc ON fct.cst_ctr_key = cc.cst_ctr_key
JOIN Dimtable4 oc ON fct.cst_ctr_own_org_key = oc.org_cd_key
JOIN Dimtable5 dt ON fct.chk_dt_key = dt.dt_key
WHERE gl.gen_led_acct_nbr = 000000
AND bu.bus_unit_txt = 'AAAAA'
AND dt.fscl_mo_nbr = 1
AND dt.fscl_yr_nbr = 2012
GROUP BY gl.gen_led_acct_nbr, gl.gen_led_acct_scr_nm, bu.bus_unit_txt, gl.gen_led_acct_typ_nm
ORDER BY gl.gen_led_acct_nbr, gl.gen_led_acct_typ_nm
Your comment:
--The sub query above can be repeated up to another 11 times, but with a different dt1.fscl_mo_nbr
Suggests that one solution would be to use "in" rather than "=", as in:
AND dt1.fscl_mo_nbr in (1, 2, . . . )
You then would want to add t1.fscl_mo_nbr to the group by clause.
I also notice that this is a big correlated subquery, which is probably also killing performance. Something like the following should simplify the query and help it run faster:
SELECT gl.gen_led_acct_nbr, gl.gen_led_acct_scr_nm, bu.bus_unit_txt,
gl.gen_led_acct_typ_nm,
sum(case when year = 2012 and dt.fscl_mo_nbr = 1 then fct.pd_txn_amt end) as Jun2012,
sum(case when year = 2012 and dt.fscl_mo_nbr = 2 then fct.pd_txn_amt end) as Jul2012,
etc.
FROM Maintable fct
JOIN Dimtable1 gl ON fct.gen_led_acct_key = gl.gen_led_acct_key
JOIN Dimtable2 bu ON fct.bus_unit_key = bu.bus_unit_key
JOIN Dimtable3 cc ON fct.cst_ctr_key = cc.cst_ctr_key
JOIN Dimtable4 oc ON fct.cst_ctr_own_org_key = oc.org_cd_key
JOIN Dimtable5 dt ON fct.chk_dt_key = dt.dt_key
where dt.fscl_mo_nbr in (1, 2, 3 . . .)
AND dt.fscl_yr_nbr = 2012
GROUP BY gl.gen_led_acct_nbr, gl.gen_led_acct_scr_nm,
bu.bus_unit_txt, dt.fscl_mo_nbr
(Please excuse any typing errors . . . I removed the "1" suffix from all the aliases.)