SELECT
  CB.ClientID,
  CB.ClientBranchID,
  CB.BranchName,
  BR.BranchName AS LabourNetBranch,
  BR.BranchManagerID,
  CB.IsHeadOffice,
  IF(CB.BranchStatus = 1, 'Active', 'Cancelled') AS BranchStatus,
  CB.TerminationDate,
  fnClientBranchRetainer(CB.ClientBranchID, NOW()) AS BranchRetainer
  FROM
    taClientBranches AS CB
      LEFT JOIN taBranches AS BR ON (BR.BranchID = CB.LabourNetBranchID)
  WHERE
    (CB.ClientBranchID = @nClientBranchID)
