mysql - stored procedure to display monday or weekday -
i want write stored procedure find out joining date of teachers , if monday should display monday else should display “weekday”
the tbl_teacher table ;
vchr_teacher_name dat_teacher_doj
teena 1982-01-10 lawrence 1979-09-01 mathew 1981-10-13 job 1980-11-12
and need create stored procedure " call check_date(1982-01-10)" results as:
day ---------- weekday ----------
i tried :
delimiter // create procedure check_date (in dat date,out day varchar(10)) begin select dayname( dat ) day tbl_teachers; end// delimiter ;
it's show error as
#1172 - result consisted of more 1 row
how , find day monday or weekday.
i think better served function:
drop function if exists `check_date` // create function `check_date` (dat date) returns varchar(10) begin return if(dayname(dat) = 'monday' , 'monday', 'weekday'); end //
i used if function determine if monday or else (weekday) needs returned.
and when use on teacher table result be:
vchr_teacher_name check_date(`dat_teacher_doj`) ------------------------------------------------ teena weekday lawrence weekday mathew weekday job weekday mday monday
i have full working sqlfiddle experiment with.
Comments
Post a Comment