I’ve got table TClientsPayment with fields
idcontract,idclient,last_paid_time,paid,left_to_pay
and I need to insert data from this table to another table TClientsPaymentsHistory with fields
idcontract,idclient,last_paid_time,paid,late
where late is a bit field. late can be either 0 or 1. it depends on whether client has paid till 25.xx.xxxx. If not late = 1.
If I make a query
insert into TClientPaymentHistory
select idcontract,
idclient,
last_paid_time,
paid
from TClientsPayments
then how to set late field in this insert query?
Use the
CASEexpression in theSELECTclause, here is a pseudo code of how you can do this:Since you didn’t specify what RDBMS you are using, you will need to determine the correct way to get the date difference depending on the SQL dialect you are using.