create function get_q_firstd(in_time date)
returning date;
define v_in_time date;
define cur_q int;
define rs_q_day date;
let v_in_time=in_time;
if v_in_time is not null then
select quarter(v_in_time) into cur_q from sysmaster:sysdual;
if cur_q = 1 then select year(sysdate)||"-01-01" into rs_q_day from sysmaster:sysdual;
elif cur_q = 2 then select year(sysdate)||"-04-01" into rs_q_day from sysmaster:sysdual;
elif cur_q = 3 then select year(sysdate)||"-07-01" into rs_q_day from sysmaster:sysdual;
elif cur_q = 4 then select year(sysdate)||"-10-01" into rs_q_day from sysmaster:sysdual;
else
exit;
end if;
else
select quarter(current) into cur_q from sysmaster:sysdual;
if cur_q = 1 then select year(sysdate)||"-01-01" into rs_q_day from sysmaster:sysdual;
elif cur_q = 2 then select year(sysdate)||"-04-01" into rs_q_day from sysmaster:sysdual;
elif cur_q = 3 then select year(sysdate)||"-07-01" into rs_q_day from sysmaster:sysdual;
elif cur_q = 4 then select year(sysdate)||"-10-01" into rs_q_day from sysmaster:sysdual;
else
exit;
end if;
end if;
return rs_q_day;
end function;