pressMac
asked on
query join with criteria fails, join not supported
I have a query that does not work. I am trying return values in tblFixedAssets whether or not there are values in tblPulls, and it there are values in tblPull, they need to be tblPulledl.PullStatus <> '"O"
Access says join not supported.
The join works in MSSQL. With a change of the double quotes to single quotes.
Access says join not supported.
SELECT DISTINCT tblFixedAssets.FixedAssetID
,tblFixedAssets.fldBarCode
,tblFixedAssets.Staff_ID
,tblFixedAssets.Model
,tblFixedAssets.fldAssetStatus
,Inventory.[Item Number]
,Inventory.fldNonBarCode
,tblPulls.PulledStatus
FROM (
tblFixedAssets INNER JOIN Inventory ON tblFixedAssets.Staff_ID = Inventory.[Item Number]
)
LEFT JOIN tblPulls ON tblFixedAssets.fldBarCode = tblPulls.ItemBarCode
AND tblpulls.pulledstatus <> "O"
WHERE tblFixedAssets.Staff_ID = 'Lens1.54-1.93-Evision'
AND tblFixedAssets.fldAssetStatus = 'Active'
The join works in MSSQL. With a change of the double quotes to single quotes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
except that simply moving that criteria down into the WHERE clause will negate the LEFT JOIN. You have to account for the NULLS (no match) in that field [PulledStatus]. You can do that with syntax like:
AND ( (tblpulls.pulledStatus IS NULL) OR (tblpulls.pulledstatus <> "O"))
but I prefer a syntax similar to:
AND NZ(tblpulls.pulledstatus, "") <> "O"
You might try:
SELECT DISTINCT tblFixedAssets.FixedAssetI D
,tblFixedAssets.fldBarCode
,tblFixedAssets.Staff_ID
,tblFixedAssets.Model
,tblFixedAssets.fldAssetSt atus
,Inventory.[Item Number]
,Inventory.fldNonBarCode
,tblPulls.PulledStatus
FROM (
tblFixedAssets INNER JOIN Inventory ON tblFixedAssets.Staff_ID = Inventory.[Item Number]
)
LEFT JOIN tblPulls ON tblFixedAssets.fldBarCode = tblPulls.ItemBarCode
WHERE tblFixedAssets.Staff_ID = 'Lens1.54-1.93-Evision'
AND tblFixedAssets.fldAssetSta tus = 'Active'
AND NZ(tblpulls.pulledstatus, "") <> "O"
AND ( (tblpulls.pulledStatus IS NULL) OR (tblpulls.pulledstatus <> "O"))
but I prefer a syntax similar to:
AND NZ(tblpulls.pulledstatus, "") <> "O"
You might try:
SELECT DISTINCT tblFixedAssets.FixedAssetI
,tblFixedAssets.fldBarCode
,tblFixedAssets.Staff_ID
,tblFixedAssets.Model
,tblFixedAssets.fldAssetSt
,Inventory.[Item Number]
,Inventory.fldNonBarCode
,tblPulls.PulledStatus
FROM (
tblFixedAssets INNER JOIN Inventory ON tblFixedAssets.Staff_ID = Inventory.[Item Number]
)
LEFT JOIN tblPulls ON tblFixedAssets.fldBarCode = tblPulls.ItemBarCode
WHERE tblFixedAssets.Staff_ID = 'Lens1.54-1.93-Evision'
AND tblFixedAssets.fldAssetSta
AND NZ(tblpulls.pulledstatus, "") <> "O"
You need to alias your subquery but honestly it doesn't appear as if you really need it set up as one anyway
SELECT DISTINCT A.FixedAssetID
,A.fldBarCode
,A.Staff_ID
,A.Model
,A.fldAssetStatus
,I.[Item Number]
,I.fldNonBarCode
,P.PulledStatus
FROM tblFixedAssets AS A
INNER JOIN Inventory AS I
ON tblFixedAssets.Staff_ID = Inventory.[Item Number]
LEFT JOIN tblPulls AS P
ON A.fldBarCode = P.ItemBarCode
AND P.pulledstatus <> "O"
WHERE A.Staff_ID = 'Lens1.54-1.93-Evision'
AND A.fldAssetStatus = 'Active'
pressMac, do you still need help with this question?
ASKER
Sorry It took so long, but that makes it work.
AND tblpulls.pulledstatus <> "O"
down into the Where clause