...
The duration of the maintenance in seconds is the End Time - Start Time. In Column D , Row 1, create a formula =(C1-B1) / 86400. Drag this formula down the length of the number of rows with data in it, to complete the column of maintenance durations.
...
In Column E, Row 1, create a formula =CONCATENATE("UPDATE report_service_availability SET out_maint='",TEXT(D1,"hh:mm:ss"),"' WHERE base_absid = ",A1," AND year = 2017 AND month = 7 ;"). Drag this formula down the length of the number of rows with data in it, to complete the column of SQL statements.
...