A
auujxa2 via AccessMonster.com
I have SQL that I am trying to put into the SQL view of an access query, that
is not working. At a glance, can you scan this and tell me what you think is
wrong? I know you have to write a certain syntax for SQL using VBA, but I
didn't know I did for SQL view in access queries.
Thank you in advance. (p.s. I know one thing is brackets near the AS
statements)
--- start of class level totals
SELECT
Dmd_Ctr
, DC_Name
, Dept
, Dept_name
, Class
, Class_name
, sum(Min_qty) as min_soq_$
, (sum(Min_qty) / sum(total_$) * 100 ) as MIN_PCT
, sum(For_qty) as fcst_soq_$
, (sum(For_qty) / sum(total_$) * 100 ) as FOR_PCT
, round(sum(total_$),2) as total_ORIG_$
from
(
SELECT
SOQHIST.CLASS1ID AS Dmd_Ctr
, CLASS1.DESCRIPTION AS DC_Name
, SOQHIST.CLASS2ID AS Dept
, CLASS2.DESCRIPTION AS Dept_Name
, CLASS3.CLASS3ID AS Class
, CLASS3.DESCRIPTION AS Class_Name
, decode(SOQHIST.minshelf , SOQHIST.topuplevel, (SOQHIST.ORIGINALQTY *
SOQHIST.RETAILPRICE) , 0 ) as Min_qty
, decode(SOQHIST.minshelf , SOQHIST.topuplevel, 0 , (SOQHIST.ORIGINALQTY *
SOQHIST.RETAILPRICE) ) as For_qty
, (SOQHIST.ORIGINALQTY * (SOQHIST.RETAILPRICE + 0.0000001)) as total_$
---- add small number to avoid dividing by 0
FROM
CLASS2 INNER JOIN CLASS1
INNER JOIN CLASS3
INNER JOIN SOQHIST
ON CLASS3.CLASS1ID = SOQHIST.CLASS1ID
AND CLASS3.CLASS2ID = SOQHIST.CLASS2ID
AND CLASS3.CLASS3ID = SOQHIST.CLASS3ID
ON CLASS1.CLASS1ID = SOQHIST.CLASS1ID
ON CLASS2.CLASS1ID = SOQHIST.CLASS1ID
AND CLASS2.CLASS2ID = SOQHIST.CLASS2ID
WHERE
SOQHIST.CLASS1ID = 361_DEMAND_CENTER
and SOQHIST.LASTREVIEWDATE = to_dateP361_CREATE_DATE,'MM-DD-YYYY')
) t2
group by
Dmd_Ctr
, DC_Name
, Dept
, Dept_name
, Class
, Class_name
) t3
--- end of class level totals
is not working. At a glance, can you scan this and tell me what you think is
wrong? I know you have to write a certain syntax for SQL using VBA, but I
didn't know I did for SQL view in access queries.
Thank you in advance. (p.s. I know one thing is brackets near the AS
statements)
--- start of class level totals
SELECT
Dmd_Ctr
, DC_Name
, Dept
, Dept_name
, Class
, Class_name
, sum(Min_qty) as min_soq_$
, (sum(Min_qty) / sum(total_$) * 100 ) as MIN_PCT
, sum(For_qty) as fcst_soq_$
, (sum(For_qty) / sum(total_$) * 100 ) as FOR_PCT
, round(sum(total_$),2) as total_ORIG_$
from
(
SELECT
SOQHIST.CLASS1ID AS Dmd_Ctr
, CLASS1.DESCRIPTION AS DC_Name
, SOQHIST.CLASS2ID AS Dept
, CLASS2.DESCRIPTION AS Dept_Name
, CLASS3.CLASS3ID AS Class
, CLASS3.DESCRIPTION AS Class_Name
, decode(SOQHIST.minshelf , SOQHIST.topuplevel, (SOQHIST.ORIGINALQTY *
SOQHIST.RETAILPRICE) , 0 ) as Min_qty
, decode(SOQHIST.minshelf , SOQHIST.topuplevel, 0 , (SOQHIST.ORIGINALQTY *
SOQHIST.RETAILPRICE) ) as For_qty
, (SOQHIST.ORIGINALQTY * (SOQHIST.RETAILPRICE + 0.0000001)) as total_$
---- add small number to avoid dividing by 0
FROM
CLASS2 INNER JOIN CLASS1
INNER JOIN CLASS3
INNER JOIN SOQHIST
ON CLASS3.CLASS1ID = SOQHIST.CLASS1ID
AND CLASS3.CLASS2ID = SOQHIST.CLASS2ID
AND CLASS3.CLASS3ID = SOQHIST.CLASS3ID
ON CLASS1.CLASS1ID = SOQHIST.CLASS1ID
ON CLASS2.CLASS1ID = SOQHIST.CLASS1ID
AND CLASS2.CLASS2ID = SOQHIST.CLASS2ID
WHERE
SOQHIST.CLASS1ID = 361_DEMAND_CENTER
and SOQHIST.LASTREVIEWDATE = to_dateP361_CREATE_DATE,'MM-DD-YYYY')
) t2
group by
Dmd_Ctr
, DC_Name
, Dept
, Dept_name
, Class
, Class_name
) t3
--- end of class level totals