Subquery Question

G

Guest

I pulled data from 4 different tables. This data now needs to be sorted into
months using the Receipt Date if it has one. If there is no Receipt Date,
then we will use the PO Date. If there is no PO Due Date, then we will use
the PR Due Date. If there is no PR Due Date, then we will use the Need Date.

I need to create a report that will look sort of like this:

Month Part No Qty Price
January AAA 2 $50.00
BBB 1 $25.00
Total Cost for January $75.00

February CCC 2 $15.00
Etc.

I was thinking that a subquery might be the answer and tried the following
that does not work. The Select statement works, but not the Where clauses
(It's also in regular SQL format.)

SELECT tblPartDetails.PricePL, tblPartDetails.QtyOrdered, tblParts.PartNo,
tblOrders.PONo, tblOrders.PRNo, tblPartDetails.ReceiptDate,
tblOrderDetails.PODueDate, tblOrderDetails.PRDueDate,
tblCabinetDetails.IWDateN, tblCabinetDetails.Plus60Days
FROM ((tblOrders INNER JOIN tblOrderDetails ON tblOrders.id_PoN =
tblOrderDetails.id_PoN) INNER JOIN ((tblCabinets INNER JOIN tblCabinetDetails
ON tblCabinets.id_Cab = tblCabinetDetails.id_Cab) INNER JOIN tblParts ON
tblCabinets.id_Cab = tblParts.id_Cab) ON tblOrders.id_PoN = tblParts.id_PoN)
INNER JOIN tblPartDetails ON tblParts.id_Part = tblPartDetails.id_Part

WHERE tblPartDetails.ReceiptDate IN

(SELECT tblPartDetails.ReceiptDate
FROM tblOrders
WHERE tblOrders.PODueDate IN

(SELECT tblOrders.PODueDate
FROM tblOrders
WHERE tblOrders.PRDueDate IN

(SELECT tblOrders.PRDueDate
FROM tblCabinetDetails.IWDateN
WHERE tblCabinetDetails.IWDateN = Is Not Null)));

Any ideas on how to do this would be appreciated!!!
 
K

kingston via AccessMonster.com

Create a calculated field and sort on it:

SortDate: IIF(IsNull([Receipt Date]),IIF(IsNull([PO Date]),IIF(IsNull([PR Due
Date]),[Need Date],[PR Due Date]),[PO Date]),[Receipt Date])

I hope I got all the parentheses correct. Anyway, you get the idea.
 
G

Guest

Just wanted to say thanks for your answer. Had to go home sick yesterday, so
I'll try your suggestion today.

kingston via AccessMonster.com said:
Create a calculated field and sort on it:

SortDate: IIF(IsNull([Receipt Date]),IIF(IsNull([PO Date]),IIF(IsNull([PR Due
Date]),[Need Date],[PR Due Date]),[PO Date]),[Receipt Date])

I hope I got all the parentheses correct. Anyway, you get the idea.
I pulled data from 4 different tables. This data now needs to be sorted into
months using the Receipt Date if it has one. If there is no Receipt Date,
then we will use the PO Date. If there is no PO Due Date, then we will use
the PR Due Date. If there is no PR Due Date, then we will use the Need Date.

I need to create a report that will look sort of like this:

Month Part No Qty Price
January AAA 2 $50.00
BBB 1 $25.00
Total Cost for January $75.00

February CCC 2 $15.00
Etc.

I was thinking that a subquery might be the answer and tried the following
that does not work. The Select statement works, but not the Where clauses
(It's also in regular SQL format.)

SELECT tblPartDetails.PricePL, tblPartDetails.QtyOrdered, tblParts.PartNo,
tblOrders.PONo, tblOrders.PRNo, tblPartDetails.ReceiptDate,
tblOrderDetails.PODueDate, tblOrderDetails.PRDueDate,
tblCabinetDetails.IWDateN, tblCabinetDetails.Plus60Days
FROM ((tblOrders INNER JOIN tblOrderDetails ON tblOrders.id_PoN =
tblOrderDetails.id_PoN) INNER JOIN ((tblCabinets INNER JOIN tblCabinetDetails
ON tblCabinets.id_Cab = tblCabinetDetails.id_Cab) INNER JOIN tblParts ON
tblCabinets.id_Cab = tblParts.id_Cab) ON tblOrders.id_PoN = tblParts.id_PoN)
INNER JOIN tblPartDetails ON tblParts.id_Part = tblPartDetails.id_Part

WHERE tblPartDetails.ReceiptDate IN

(SELECT tblPartDetails.ReceiptDate
FROM tblOrders
WHERE tblOrders.PODueDate IN

(SELECT tblOrders.PODueDate
FROM tblOrders
WHERE tblOrders.PRDueDate IN

(SELECT tblOrders.PRDueDate
FROM tblCabinetDetails.IWDateN
WHERE tblCabinetDetails.IWDateN = Is Not Null)));

Any ideas on how to do this would be appreciated!!!
 

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

Top