|
Question : sql date logic
|
|
I have created a query that returns the date the record was created, the arrival date of the client and the invoice value and if any payments have been made against the invoice value.
I am trying to get clients who have either not paid a deposit or not paid sufficient deposit against the invoice value.
the problem i have encountered is that my criteria says filter for clients where the client record is >21 days, then filter for an arrival date 25 days or less prior to their arrival (so they dont arrive having paid nothing or insufficient)
the above works fine.
I would like to capture the event where admin staff might create the record 2 days before client arrival in an attempt to evade the invoice system.
which in effect seems to contra my previous filter where the staff have 21 days to get the approval of the invoice pass the MD.
not sure how to evaluate this logic.
help would be appreciated.
regards
Code Snippet:
1:
2:
3:
|
SELECT TblGroup.GroupID, TblGroup.[Group Created], DateDiff("d",[group created],Now()) AS NumDays, TblGroup.[Arrival Date], DateDiff("d",Now(),[arrival date]) AS Daystoarr, QryGroupReceiptsSumincCredit.SumOfSumOfAmount, QryGrouptotalsandbalances.[Invoice Value], QryGrouptotalsandbalances.Paid, QryGrouptotalsandbalances.Balance, 0.15*[invoice value] AS percentDep
FROM (TblGroup LEFT JOIN QryGroupReceiptsSumincCredit ON TblGroup.GroupID = QryGroupReceiptsSumincCredit.[GROUP-DSN]) LEFT JOIN QryGrouptotalsandbalances ON TblGroup.GroupID = QryGrouptotalsandbalances.[Grp no]
WHERE (((DateDiff("d",[group created],Now()))>21) AND ((DateDiff("d",Now(),[arrival date]))>=0) AND ((QryGrouptotalsandbalances.Paid)<(0.15*[invoice value]))) OR (((DateDiff("d",[group created],Now()))>21) AND ((DateDiff("d",Now(),[arrival date]))>=0 And (DateDiff("d",Now(),[arrival date]))<25) AND ((QryGrouptotalsandbalances.Paid)<(0.15*[invoice value])));
|
|
|
Answer : sql date logic
|
|
hi
since it will take 21 days to get the approval of the invoice, it means that the arrival date must be at least 21 days after the record was created. so you can check if the arrival date is less than 21 days prior to the date created, then the record was created on a later time than the actual date. so you should include these records.
i changed
(DateDiff("d",[group created],Now()))>21
to
DateDiff("d",[group created],Now())>21 OR DateDiff("d",[group created],[arrival date])<21
1:
2:
3:
4:
5:
6:
7:
|
SELECT TblGroup.GroupID, TblGroup.[Group Created], DateDiff("d",[group created],Now()) AS NumDays, TblGroup.[Arrival Date], DateDiff("d",Now(),[arrival date]) AS Daystoarr, QryGroupReceiptsSumincCredit.SumOfSumOfAmount, QryGrouptotalsandbalances.[Invoice Value], QryGrouptotalsandbalances.Paid, QryGrouptotalsandbalances.Balance, 0.15*[invoice value] AS percentDep
FROM (TblGroup LEFT JOIN QryGroupReceiptsSumincCredit ON TblGroup.GroupID = QryGroupReceiptsSumincCredit.[GROUP-DSN]) LEFT JOIN QryGrouptotalsandbalances ON TblGroup.GroupID = QryGrouptotalsandbalances.[Grp no]
WHERE ((DateDiff("d",[group created],Now())>21 OR DateDiff("d",[group created],[arrival date])<21) AND ((DateDiff("d",Now(),[arrival date]))>=0) AND ((QryGrouptotalsandbalances.Paid)<(0.15*[invoice value]))) OR ((DateDiff("d",[group created],Now())>21 OR DateDiff("d",[group created],[arrival date])<21) AND ((DateDiff("d",Now(),[arrival date]))>=0 And (DateDiff("d",Now(),[arrival date]))<25) AND ((QryGrouptotalsandbalances.Paid)<(0.15*[invoice value])));
(DateDiff("d",[group created],Now()))>21
|
|
|
|
|