I have a table and task field id = web_actividade.TicketID. I need to insert into this table values from other table and increment the DayWork field based on last MAX(DayWork) related to the field id TicketID. So if I have TicketID 12 with MAX(DayWork)=2 the code must insert 3 into DayWork field.

INSERT INTO web_actividade(Name,TicketID,tipo_actividade,client,Description,CPost,obs,DayWork)
SELECT t1.Resp,t1.NR_Obra,t1.tipo,t1.client,t1.Description,t1.CPost,'NEW DAY',DiaWork + 1
FROM nr_obra t1
INNER JOIN web_actividade t2
ON t1.NR_Obra=t2.TicketID
WHERE t1.NR_Obra=t2.TicketID AND t2.ClosedTicket="NO";

The code sintaxe is ok and runs but the DayWork does not increments.

EDITED: I change t2.DiaWork=(t2.DiaWork)+1 to DiaWork + 1. Now increments but not in the right way...As shown on image. Started with DiaWork = 1 after run the code only 3 times. The rigth result must be ID 976=2, 977=3, 978=4 and so on, image: Click to see image

0 Answers