SELECT
  CT.CaseActionID,
  S1.OptionDescription AS ActionName,
  DATE_FORMAT(FROM_UNIXTIME(CT.Created), '%Y-%m-%d') AS DateCreated,
  U1.FullName AS ActionedBy,
  DATE_FORMAT(FROM_UNIXTIME(CT.DateDiarised), '%Y-%m-%d') AS DateDiarised,
  U2.FullName AS CreatedBy,
  CA.CaseCategoryID
FROM
  taCaseAction AS CT
    LEFT JOIN taCase AS CA ON (CA.CaseID = CT.CaseID)
    LEFT JOIN taUsers AS U1 ON (U1.UserID = CT.ActionedByID)
    LEFT JOIN taUsers AS U2 ON (U2.UserID = CT.CreatedByID)
    LEFT JOIN taSystemOption AS S1 ON ((S1.OptionType = 'CASE-ACTION-TYPE') AND (S1.OptionID = CT.ActionID))
WHERE
  (CT.CaseID IS NOT NULL) AND
  (CT.CaseID <> 0) AND
  (CT.CaseID = @nCaseID)
