Link to home
Start Free TrialLog in
Avatar of pressMac
pressMacFlag for United States of America

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.

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'

Open in new window


The join works in MSSQL.  With a change of the double quotes to single quotes.
Avatar of aikimark
aikimark
Flag of United States of America image

I would move this
AND tblpulls.pulledstatus <> "O"
down into the Where clause
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.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
WHERE tblFixedAssets.Staff_ID = 'Lens1.54-1.93-Evision'
      AND tblFixedAssets.fldAssetStatus = 'Active'
      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'

Open in new window

pressMac, do you still need help with this question?
Avatar of pressMac

ASKER

Sorry It took so long, but that makes it work.