SELECT
DISTINCT ipdinfo.hn as codeuser,
(
SELECT syscon.Name as name
FROM prefix
LEFT JOIN syscon ON prefix.codeuser = syscon.Code
WHERE codeuser = info.Code
AND Suffix = patname.Suffix
AND syscon.Code = 100
) PrefixName
FROM ipdinfo
LEFT JOIN codemas ON info.codeuser = codemas.codeuser
LEFT JOIN patname ON info.hn = patname.hn
LEFT JOIN syscon ON codemas.Code = syscon.Code
WHERE info.HDBDateTime is not null
AND info.DateTime BETWEEN '".$Datestart."' AND '".$EndDate."'
AND syscon.Code = 52615 and codemas.Code is not null
AND codemas.Codecxl in ('45','99')
AND patname.Suffix='0'