What is wrong with this Code:
SELECT TASK_ORDER.C_Name, TASK_ORDER.CO_Name, TASK_ORDER.[Cont_#], TASK_ORDER.[TO_#], DELIVERABLE.[Del_#], DELIVERABLE.[Invoiced Amount], DELIVERABLE.Rec_Date, DELIVERABLE.HQ_App_Date, DELIVERABLE.Invoiced_Date, DELIVERABLE.KDF_Approval, DELIVERABLE.R_Drive_Date, DELIVERABLE.DB_Update_Date, DELIVERABLE.Website_Date, DELIVERABLE.Comments,
IIf((DELIVERABLE.Rec_Date<=DELIVERABLE.HQ_App_Date) Or (DELIVERABLE.HQ_App_Date Is Null),
IIf((DELIVERABLE.Rec_Date<=DELIVERABLE.Invoiced_Date) Or (DELIVERABLE.Invoiced_Date Is Null),DELIVERABLE.Rec_Date,
IIf((DELIVERABLE.HQ_App_Date<=DELIVERABLE.Invoiced_Date) Or (DELIVERABLE.Invoiced_Date Is Null),DELIVERABLE.HQ_App_Date,DELIVERABLE.Invoiced_Date))) AS Test_Date
FROM TASK_ORDER INNER JOIN DELIVERABLE ON TASK_ORDER.[Cont_#]=DELIVERABLE.[Cont_#]
I have three date fields in a table and when I run the query to create a report I would like to sort my records based on the earliest date across the three fields for each record. My answer was to write an IIF statement that would find the earliest date between the three date fields in each record and populate a fourth date field with that earliest date called "Test_Date". Then I could sort my report based on the fourth date field which is the earliest date for each record. If "Rec_Date" or "Invoiced_Date" are the earliest, this query works just fine. However, if "HQ_App_Date" is the earliest date, I get a null value in the "Test_Date" field I'm trying to populate. Any suggestions? Thanks all!
SELECT TASK_ORDER.C_Name, TASK_ORDER.CO_Name, TASK_ORDER.[Cont_#], TASK_ORDER.[TO_#], DELIVERABLE.[Del_#], DELIVERABLE.[Invoiced Amount], DELIVERABLE.Rec_Date, DELIVERABLE.HQ_App_Date, DELIVERABLE.Invoiced_Date, DELIVERABLE.KDF_Approval, DELIVERABLE.R_Drive_Date, DELIVERABLE.DB_Update_Date, DELIVERABLE.Website_Date, DELIVERABLE.Comments,
IIf((DELIVERABLE.Rec_Date<=DELIVERABLE.HQ_App_Date) Or (DELIVERABLE.HQ_App_Date Is Null),
IIf((DELIVERABLE.Rec_Date<=DELIVERABLE.Invoiced_Date) Or (DELIVERABLE.Invoiced_Date Is Null),DELIVERABLE.Rec_Date,
IIf((DELIVERABLE.HQ_App_Date<=DELIVERABLE.Invoiced_Date) Or (DELIVERABLE.Invoiced_Date Is Null),DELIVERABLE.HQ_App_Date,DELIVERABLE.Invoiced_Date))) AS Test_Date
FROM TASK_ORDER INNER JOIN DELIVERABLE ON TASK_ORDER.[Cont_#]=DELIVERABLE.[Cont_#]
I have three date fields in a table and when I run the query to create a report I would like to sort my records based on the earliest date across the three fields for each record. My answer was to write an IIF statement that would find the earliest date between the three date fields in each record and populate a fourth date field with that earliest date called "Test_Date". Then I could sort my report based on the fourth date field which is the earliest date for each record. If "Rec_Date" or "Invoiced_Date" are the earliest, this query works just fine. However, if "HQ_App_Date" is the earliest date, I get a null value in the "Test_Date" field I'm trying to populate. Any suggestions? Thanks all!