SELECT
  LEFT(PH.DateTimeInitiated, 10) AS PhoneCallDate,
  PH.PhoneCallID,
  PH.InovoCallID,
  PH.InovoCaller,
  PH.ContactName,
  PH.ContactPosition,
  PH.ContactEmail,
  RIGHT(COALESCE(PH.DateTimeInitiated, ''), 8) AS StartTime,
  RIGHT(COALESCE(PH.DateTimeConcluded, ''), 8) AS EndTime,
  IF(TIMESTAMPDIFF(SECOND, PH.DateTimeInitiated, PH.DateTimeConcluded) > 0, TIMEDIFF(PH.DateTimeConcluded, PH.DateTimeInitiated), '') AS Duration,
  PH.ConsultantID,
  BR.BranchName,
  U1.FullName AS Consultant,
  PH.PhoneCallTypeID,
  REPLACE(S1.OptionDescription, '_', ' ') AS PhoneCallType,
  PH.ClientID,
  CS.FinNumber,
  CS.GroupName,
  PR.ProductName,
  PH.AttendanceTypeID,
  AT.AppointmentType,
  PH.Particulars
FROM
  taPhoneCall AS PH
    LEFT JOIN taClients AS CS ON (CS.ClientID = PH.ClientID)
    LEFT JOIN taProducts AS PR ON (PR.ProductID = PH.ProductID)
    LEFT JOIN taUsers AS U1 ON (U1.UserID = PH.ConsultantID)
    LEFT JOIN taSystemOption AS S1 ON ((S1.OptionType = 'PHONE-CALL-TYPE') AND (S1.OptionID = PH.PhoneCallTypeID))
    LEFT JOIN tbAppointmentTypes AS AT ON (AT.AttendanceTypeID = PH.AttendanceTypeID)
    LEFT JOIN taClientBranches AS CB ON (CB.ClientID = CS.ClientID)
    LEFT JOIN taBranches AS BR ON (BR.BranchID = CB.LabourNetBranchID)
WHERE
  1
  @pProductID
  @pConsultantID
  @pClientID
  @pPhoneCallTypeID
  @pFromTo
  @pBranchID
GROUP BY PhoneCallDate, StartTime, PH.ConsultantID, PH.PhoneCallTypeID, CS.ClientID