1
select `usr`.`Name` AS `Username`,`usr`.`UserID` AS `UserID`,(select `labtech`.`properties`.`Value` from `labtech`.`properties` where (`labtech`.`properties`.`Name` = 'ReportCompanyName') limit 1) AS `ReportCompanyName`,`clt`.`ClientID` AS `ClientID`,`clt`.`Name` AS `ClientName`,max((case when (`sp`.`PropertyName` = 'HowToWeighScores') then `sp`.`Value` end)) AS `ScoringMethod`,max((case when (`sp`.`PropertyName` = 'GreenMin') then (`sp`.`Value` * 100) end)) AS `GreenMin`,max((case when (`sp`.`PropertyName` = 'YellowMin') then (`sp`.`Value` * 100) end)) AS `YellowMin`,max((case when (`sp`.`PropertyName` = 'YellowIsUnhealthy') then `sp`.`Value` end)) AS `YellowIsUnhealthy`,ifnull(max((case when (`sp`.`PropertyName` = 'ReportCheckDisplayCount') then `sp`.`Value` end)),5) AS `ReportCheckDisplayCount` from (((`labtech`.`clients` `clt` join `labtech`.`usersec` `usec` on((`clt`.`ClientID` = `usec`.`ClientID`))) join `labtech`.`users` `usr` on(((`usec`.`UserID` = `usr`.`UserID`) and (`usr`.`Name` = `f_username`())))) join `labtech`.`plugin_sap_properties` `sp`) where ((select count(`r`.`TargetID`) from `labtech`.`plugin_sap_reportcategoryresults` `r` where ((`r`.`TargetType` = 3) and (`r`.`TargetID` = `clt`.`ClientID`))) > 0) group by `clt`.`ClientID`