Update and Insert table rows using mysql store procedure -
i have table book_meetings have 70000 record , want migrate data table little modification have created mysql storeprocedure. records inserted in new table values set null. selecting 4 columns book_meetings table , wants insert them in table.
id int date date meet_at time duration_in_hours decimal
what want calculate start_date , end_date based on above value example
if date ="2017-09-08" , meet_at "09:00:00" , duration_in_hours 1.5
then start_date "2017-09-08 09:10:00"
end_date= start_date_duration_in_hour end_date "2017-09-08 09:10:00" start_date = concat date , meet_at end_date = start_date + duration_in_hours , insert values in new table
if there better idea please suggest
create procedure book_meetings8() begin -- declare local variables declare done boolean default 0; declare meet_at time; declare start_date datetime; declare tmp_date varchar(255); declare end_date datetime; declare end_recurring_date date; declare date1 date ; declare id integer(11); declare duration decimal(8,2); declare minutes integer(11); -- declare cursor declare iter cursor select id,date, meet_at,duration_in_hours book_meetings limit 100; -- declare continue handler declare continue handler sqlstate '02000' set done=1; -- open cursor open iter; -- loop through rows repeat -- order number fetch iter id,date1,meet_at,duration; set minutes = duration * 60; set start_date = cast(date1 char) + " "+cast(meet_at char); set end_date = cast(start_date datetime) + interval minutes minute; insert book_meetings_1(start_date,end_date) values(start_date,end_date); -- end of loop until done end repeat; -- close cursor close iter; end;
well have solved above problem single sql statement (insertion , updation record @ once without store procedure)
insert temp_diary.book_meetings ( id,start_date,end_date) select id,concat(`date`, ' ', `meet_at`) start_date,date_add(concat(date,' ',meet_at), interval `duration_in_hours` hour) end_date estate.book_meetings;
Comments
Post a Comment