CREATE -- ALGORITHM=UNDEFINED DEFINER="root"@"localhost" SQL SECURITY DEFINER 
  VIEW CCVDBQUERIES AS 
  select qt.RWNAME AS "ABFRAGENAME",
         qg.RWVALUE AS "GRUPPE",
		 gi.RWVALUE AS "GRUPPENTITEL",
		 gi.RWPARENT AS "ELTERNGRUPPE",
         gi.RWDESC AS "GRUPPENBESCHREIBUNG",
		 qp.RWTYP AS "RWTYP",
		 qp.RWPARENT AS "RWPARENT",
		 qp.RWNAME AS "RWNAME",
	     qp.RWVALUE AS "RWVALUE",
		 qp.RWDESC AS "RWDESC",
	     (case when (qh.RWVALUE in ('Y','y','T','t','J','j','TRUE','true')) then 'hidden' 
	           when (qh.RWVALUE is not null) then qh.RWVALUE 
	           when (qg.RWVALUE in ('hidden','HIDDEN')) then 'hidden' else NULL end) AS "VERBORGEN"
    from        CCRW qt 
      left join CCRW qp on ((qp.RWTYP = 'DQUERYPARAM') and (qp.RWPARENT = convert(qt.RWNAME using utf8))) or 
			                      ((qp.RWTYP = 'DQUERY') and (qp.RWPARENT = 'QUERIES') and (qp.RWNAME = qt.RWNAME)) 
              left join CCRW qg on (((qg.RWTYP = 'DQUERYPARAM') and (qg.RWPARENT = convert(qt.RWNAME using utf8)) and (qg.RWNAME = 'group')))
              left join CCRW gi on (((gi.RWTYP = 'QUERYGROUP') and (gi.RWNAME = convert(qg.RWVALUE using utf8)))) 
              left join CCRW qh on (((qh.RWTYP = 'DQUERYPARAM') and (qh.RWPARENT = convert(qt.RWNAME using utf8)) and (qh.RWNAME = 'hidden'))) 
   where ((qt.RWTYP = 'DQUERY') and (qt.RWPARENT = 'QUERIES'))
