I'm getting an error when pasting in a raw SQL query into Access's SQL View. I know Access syntax is a bit special but I can't figure out what it's asking for. The error says: Syntax error (missing operator) in query expression '(jobmatl.suffix = job.suffix) AND (job.job = jobmatl.job) INNER ...................... AS ibl ON jobmatl.item = ibl.item AND job.whse = ibl.whse. The error mentions everything in between what I've written.
SELECT
job.job,
job.suffix,
job.job_date,
job.item AS FG,
jobmatl.item,
job.whse,
ibl.sumofqtyonhand,
ibl.whse
FROM
job
INNER JOIN jobmatl ON (jobmatl.suffix = job.suffix) AND (job.job = jobmatl.job)
INNER JOIN (
(SELECT
i.item,
SUM(i.qty_on_hand) AS sumofqtyonhand,
i.whse
FROM
Item_by_Location_LP_ALL AS i
WHERE
i.hold_flag != 1
GROUP BY
i.item,
i.whse
)) AS ibl ON jobmatl.item = ibl.item AND job.whse = ibl.whse
WHERE
(((job.job_date)=Date()-(DatePart("w",Date(),2,1)-1)));
The FROM should look like this for MS Access:
FROM (job INNER JOIN
jobmatl
ON jobmatl.suffix = job.suffix AND job.job = jobmatl.job
) INNER JOIN
(SELECT i.item, SUM(i.qty_on_hand) AS sumofqtyonhand, i.whse
FROM Item_by_Location_LP_ALL AS i
WHERE i.hold_flag <> 1
GROUP BY i.item, i.whse
) AS ibl
ON jobmatl.item = ibl.item AND job.whse = ibl.whse;
MS Access requires extra parentheses for each JOIN. In addition, you have to levels of parentheses -- and I don't know if that is allowed.
Related
SELECT * FROM exclusivity
left join patent on (exclusivity.[Appl_Type]=patent.[Appl_Type] AND exclusivity.[Appl_No]=patent.[Appl_No] AND exclusivity.[Product_No]=patent.[Product_No])
left join products on (exclusivity.[Appl_Type]=products.[Appl_Type] AND exclusivity.[Appl_No]=products.[Appl_No] AND exclusivity.[Product_No]=products.[Product_No]);
The above query gives Syntax error
(missing operator) in query expression 'exclusivity.[Appl_Type]=patent.[Appl_Type] AND exclusivity.[Appl_No]=patent.[Appl_No] AND exclusivity.[Product_No]=patent.[Product_No])
left join products on (exclusivity.[Appl_Type]=products.[Appl_Type] AND exclusivity.[Appl_No]=products.[Appl_No] AND exclusivity.[Product_No]=products.[Product_No]);'
What could be possible reason?
MS Access has weird requirements for parentheses around joins:
SELECT *
FROM (exclusivity left join
patent
on exclusivity.[Appl_Type] = patent.[Appl_Type] AND
exclusivity.[Appl_No] = patent.[Appl_No] AND
exclusivity.[Product_No] = patent.[Product_No]
) left join
products
on exclusivity.[Appl_Type] = products.[Appl_Type] AND
exclusivity.[Appl_No] = products.[Appl_No] AND
exclusivity.[Product_No] = products.[Product_No];
I'm trying to execute a SQL statement, but I get an error that says there's a syntax error in the join.
I'm executing the following query:
SELECT
T.Omschrijving as Team, P.Beschrijving AS Proces,
Round(Sum(P.Aantal), 2) AS Prognose, P.Maand AS PrognoseMaand,
P.jaar, A.Omschrijving AS Fonds
FROM
tblPrognose AS P, tblTeam AS T, tblAfdeling AS A
LEFT JOIN
(SELECT
RL.Omschrijving, I.TEAMID, I.PROCESOMS,
SUM(NORMUREN_I) AS Instroom, I.Maand, I.Jaar
FROM
tblInstroom AS I
LEFT JOIN
(SELECT
T.Omschrijving, R.GPSTeam, R.Procesoms
FROM
tblRollen AS R, tblTeam AS T
WHERE
T.TeamID = R.TeamID) AS RL ON (I.TEAMID = RL.GPSTEAM AND I.PROCESOMS = RL.PROCESOMS)
GROUP BY
I.TEAMID, I.Procesoms, I.maand, I.jaar, RL.Omschrijving) AS tblR ON (tblR.Omschrijving = T.Omschrijving) AND (tblR.Procesoms = P.Beschrijving) AND (tblR.Maand = P.Maand) AND (tblR.jaar = P.jaar)
WHERE
P.KPI = 'Instroom'
AND P.Maand BETWEEN Month(P.Datum_vanaf) AND Month(P.Datum_tot)
AND P.jaar BETWEEN year(P.Datum_vanaf) AND year(P.Datum_tot)
AND P.TeamID = T.TeamID
AND A.AfdelingID = T.AfdelingID
AND NOT Nz(P.Beschrijving, '') = ''
GROUP BY
T.Omschrijving, P.Maand, P.jaar, P.Beschrijving, A.Omschrijving
I have tested if the error is within the JOINs but it isn't. If I execute the SELECTs seperately they work just fine and give me the correct results.
Any help would be appreciated!
I'm getting a syntax error pointing to my FROM clause, but I can't figure it out. The goal here is to use subqueries to filter and return some information before joining.
What I've tried: This question on SO suggested that I surround the 2 LEFT JOINS with parentheses. I did so, but it didn't help. Below is the result, and the error I get is in the title.
It may or may not be important to note that before doing the parentheses around both JOINS, I was getting the following error: Syntax error (missing operator in query expression 'tbl_HersheySAPInventory.item = maxdatejob.item LEFT JOIN (SELECT * FROM dbo_Item_by_Location_LP_All WHERE qty_on_hand >'.
SELECT
tbl_HersheySAPInventory.ID,
tbl_HersheySAPInventory.item,
dbo_job.job_date,
dbo_job.job,
dbo_job.suffix,
Sum(comptable.qty_on_hand) AS SumOfqty_on_hand,
comptable.whse,
comptable.product_code
FROM
tbl_HersheySAPInventory
(LEFT JOIN
(SELECT
dbo_job.job_date,
dbo_job.job,
dbo_job.suffix,
dbo_job.item AS FG,
dbo_jobmatl.item
FROM
dbo_job
INNER JOIN dbo_jobmatl ON dbo_job.job = dbo_jobmatl.job AND dbo_job.suffix = dbo_jobmatl.suffix
WHERE
dbo_job.item Not Like "Indirect" AND
dbo_job.job Not Like "C0*" AND
dbo_job.job Not Like "*R0*"
) AS maxdatejob
ON tbl_HersheySAPInventory.item = maxdatejob.item)
(LEFT JOIN
(SELECT * FROM dbo_Item_by_Location_LP_All WHERE qty_on_hand > 0 AND whse = Forms!MainForm!Combo353) AS comptable
ON comptable.item = tbl_HersheySAPInventory.item)
ORDER BY
tbl_HersheySAPInventory.item,
dbo_job.job_date;
You may have a problem with your parentheses. I have similar issues writing SQL into Access - there seem to be some strange requirements wrapping parens around JOINS and WHERE clauses.
The pseudocode that I recommend trying is:
FROM
(
(
Table A
)
LEFT JOIN
(
Subquery1
)
)
LEFT JOIN
(
Subquery2
)
I've taken a stab at updating below. Give this a try and let me know:
SELECT
tbl_HersheySAPInventory.ID,
tbl_HersheySAPInventory.item,
dbo_job.job_date,
dbo_job.job,
dbo_job.suffix,
comptable.whse,
comptable.product_code,
Sum(comptable.qty_on_hand) AS SumOfqty_on_hand
FROM
(
(
tbl_HersheySAPInventory
LEFT JOIN
(SELECT
dbo_job.job_date,
dbo_job.job,
dbo_job.suffix,
dbo_job.item AS FG,
dbo_jobmatl.item
FROM
dbo_job
INNER JOIN dbo_jobmatl ON dbo_job.job = dbo_jobmatl.job AND dbo_job.suffix = dbo_jobmatl.suffix
WHERE
dbo_job.item Not Like "Indirect" AND
dbo_job.job Not Like "C0*" AND
dbo_job.job Not Like "*R0*"
) AS maxdatejob
ON tbl_HersheySAPInventory.item = maxdatejob.item
)
)
LEFT JOIN
(SELECT * FROM dbo_Item_by_Location_LP_All WHERE qty_on_hand > 0 AND whse = Forms!MainForm!Combo353) AS comptable
ON comptable.item = tbl_HersheySAPInventory.item
GROUP BY
tbl_HersheySAPInventory.ID,
tbl_HersheySAPInventory.item,
dbo_job.job_date,
dbo_job.job,
dbo_job.suffix,
comptable.whse,
comptable.product_code
ORDER BY
tbl_HersheySAPInventory.item,
dbo_job.job_date;
I'm having trouble getting my query working. Could someone cast an experienced eye on it please? The table structure is simple (2 one-to-many relationships). The query is trying to work out for each sign, how many contributions there are at each unique "PositionLocation".
Sign <- Signifier (f_key sign_oid) <- Contribution (f_key signifier_oid)
I'm getting the following error:
Error: An ON clause associated with a JOIN operator is not valid.
SQLState: 42972
ErrorCode: -1
My query is:
select s.NAME, c.POSITIONLOCATION, count(*) as num_per_locn,
(
select count(*) from APP.CONTRIBUTION c2
inner join APP.SIGNIFIER si2 on si2.OID = c2.SIGNIFIER_OID
inner join APP.SIGN s2 on s2.OID = si2.SIGN_OID
and s2.OID = s.OID
) as num_per_sign
from APP.CONTRIBUTION c
inner join APP.SIGNIFIER si on si.OID = c.SIGNIFIER_OID
inner join APP.SIGN s on s.OID = si.SIGN_OID
group by s.NAME, c.POSITIONLOCATION
I am trying to pull two different values based on different criteria from the same table and in my Left Join of the same table it is not recognizing the SELECT statement.
The error is as follows:
Dynamic SQL Error
SQL error code = -104
Token unknown - line 7, char -1
SELECT.
The SQL Statement:
SELECT
b.dept,b.typ,c.brand,c.style,c.ext,c.description,
max(c.price),max(c.last_cost),sum(c.quan) "TOTAL INV",D.QUAN "WEB INV"
FROM
invt c
left outer join (
SELECT dept,typ,brand,style,ext,description,sum(quan) as d.quan
FROM invt WHERE store in ('997')
group by dept,typ,brand,style,ext,description) d
on (b.store = d.store and b.style = d.style and b.brand = d.brand)
LEFT OUTER JOIN
sku b
on c.style = b.style and c.brand = b.brand
where c.quan <> 0 or c.ord <> 0
GROUP BY
b.dept,b.typ,c.brand,c.style,c.ext,c.description
Try changing this line:
SELECT dept,typ,brand,style,ext,description,sum(quan) as d.quan
to this:
SELECT store,dept,typ,brand,style,ext,description,sum(quan) as quan
You do not need the d alias here.
UPDATE:
As #Jeremy Holovacs mentioned, you also seem to be using d.store for your join but it does not exist in your subquery.