blob: dd63734b4c992618d8c0bf34b9856c5471918d6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
CREATE FUNCTION getupdflg ( master_id INT(11) )
RETURNS CHAR
NOT DETERMINISTIC
BEGIN
DECLARE upd_flg CHAR;
SET upd_flg = (
select case
when ev.source != 'vdr' and ev.starttime <= cm.mergesp and ev.masterid != ev.useid then 'C'
when ev.source != 'vdr' and ev.starttime <= cm.mergesp and jo.masterid is not Null then 'T'
when ev.delflg = 'Y' then 'D'
when ev.source != 'vdr' and ev.starttime <= cm.mergesp and jo.masterid is Null then 'R'
when ev.source != 'vdr' and ev.starttime > cm.mergesp then 'A'
when ev.source = 'vdr' and cm.mergesp is Null then 'P'
when ev.source = 'vdr' and ev.starttime > cm.mergesp then 'I'
when ev.source = 'vdr' and ev.starttime <= cm.mergesp and ev.masterid = ev.useid then 'A'
when ev.source = 'vdr' and ev.starttime <= cm.mergesp and ev.masterid != ev.useid then 'L'
end
from
events ev
left join
events jo
on
ev.masterid = jo.useid and jo.useid != 0 and jo.updflg = 'L'
left join
(select distinct mergesp,channelid from channelmap where channelmap.source != 'vdr') cm
on
ev.channelid = cm.channelid
where
ev.masterid = master_id
limit 1
);
RETURN upd_flg;
END
|