Left Join Query Problem

P

Pat Coleman

Here is my query :

SELECT PartQOH.PARTID, PartQOH.SumOfQTY, PartsOnOpenSO.Allocated,
(PartQOH.SumOfQTY-PartsOnOpenSO.Allocated) AS Available
FROM PartQOH LEFT JOIN PartsOnOpenSO ON PartQOH.PARTID =
PartsOnOpenSO.PARTID;


We are tring to determine Quantity 'Available' which is
(PartQOH.SumOfQTY-PartsOnOpenSO.Allocated)

The query runs OK and returns a correct values for [ Available ] as long as
there is a value in the field [PartsOnOpenSO.Allocated]

If the field [PartsOnOpenSO.Allocated] is blank, the there is no value
returned for the [Available] field, even though the [PartQOH.SumOfQTY] has a
value.

The query looks like this

PARTID SumOfQTY Allocated Available
35 304 4 300
25 150 50 100
26 200
32 68
56 12 3 9


So if there are no parts [Allocated] , I need [Available] to read the value
in the [SumOfQTY] field.

Any Ideas ???
 
K

KARL DEWEY

Try this ---
SELECT PartQOH.PARTID, PartQOH.SumOfQTY, PartsOnOpenSO.Allocated,
(PartQOH.SumOfQTY-IIF(PartsOnOpenSO.Allocated IS NULL, 0,
PartsOnOpenSO.Allocated)) AS Available
FROM PartQOH LEFT JOIN PartsOnOpenSO ON PartQOH.PARTID =
PartsOnOpenSO.PARTID;

Or this --
SELECT PartQOH.PARTID, PartQOH.SumOfQTY, PartsOnOpenSO.Allocated,
(PartQOH.SumOfQTY-Nz(PartsOnOpenSO.Allocated,0)) AS Available
FROM PartQOH LEFT JOIN PartsOnOpenSO ON PartQOH.PARTID =
PartsOnOpenSO.PARTID;
 
P

Pat Coleman

Thank you very much - both work perfect.





KARL DEWEY said:
Try this ---
SELECT PartQOH.PARTID, PartQOH.SumOfQTY, PartsOnOpenSO.Allocated,
(PartQOH.SumOfQTY-IIF(PartsOnOpenSO.Allocated IS NULL, 0,
PartsOnOpenSO.Allocated)) AS Available
FROM PartQOH LEFT JOIN PartsOnOpenSO ON PartQOH.PARTID =
PartsOnOpenSO.PARTID;

Or this --
SELECT PartQOH.PARTID, PartQOH.SumOfQTY, PartsOnOpenSO.Allocated,
(PartQOH.SumOfQTY-Nz(PartsOnOpenSO.Allocated,0)) AS Available
FROM PartQOH LEFT JOIN PartsOnOpenSO ON PartQOH.PARTID =
PartsOnOpenSO.PARTID;


--
KARL DEWEY
Build a little - Test a little


Pat Coleman said:
Here is my query :

SELECT PartQOH.PARTID, PartQOH.SumOfQTY, PartsOnOpenSO.Allocated,
(PartQOH.SumOfQTY-PartsOnOpenSO.Allocated) AS Available
FROM PartQOH LEFT JOIN PartsOnOpenSO ON PartQOH.PARTID =
PartsOnOpenSO.PARTID;


We are tring to determine Quantity 'Available' which is
(PartQOH.SumOfQTY-PartsOnOpenSO.Allocated)

The query runs OK and returns a correct values for [ Available ] as long
as
there is a value in the field [PartsOnOpenSO.Allocated]

If the field [PartsOnOpenSO.Allocated] is blank, the there is no value
returned for the [Available] field, even though the [PartQOH.SumOfQTY]
has a
value.

The query looks like this

PARTID SumOfQTY Allocated Available
35 304 4 300
25 150 50 100
26 200
32 68
56 12 3 9


So if there are no parts [Allocated] , I need [Available] to read the
value
in the [SumOfQTY] field.

Any Ideas ???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top