From e2a48d8701f91b8e24fbe9e99e91eb72a87bb749 Mon Sep 17 00:00:00 2001
From: horchi <vdr@jwendel.de>
Date: Sun, 5 Mar 2017 16:39:28 +0100
Subject: git init

---
 configs/getupdflg.sql | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 configs/getupdflg.sql

(limited to 'configs/getupdflg.sql')

diff --git a/configs/getupdflg.sql b/configs/getupdflg.sql
new file mode 100644
index 0000000..dd63734
--- /dev/null
+++ b/configs/getupdflg.sql
@@ -0,0 +1,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
-- 
cgit v1.2.3

