SELECT
  PS.ProspectID,
  PS.ProspectName,
  PS.LabourNetBranchID,
  PS.OriginID,
  PS.IndustryID,
  PS.SetaID,
  PS.PaymentMethod,
  X.QuotedAmount,
  PS.EstTurnOver,
  PS.OrderCompulsory,
  COALESCE(PS.PeasaMember, 0) AS PeasaMember,
  PS.CompanyRegNumber,
  PS.VATNumber,
  COALESCE(PS.TaxTypeID, 1) AS TaxTypeID,
  PS.SalesReferrerID,
  PS.EmailAddress,
  PS.Postal1,
  PS.Postal2,
  PS.Postal3,
  PS.PostalCode,
  PS.PaymentMethod,
  PS.BankSortCode,
  PS.BankAccountNumber,
  PS.DateCreated,
  PS.ClientID,
  PS.ClientDate,
  PS.RequestDateTime,
  PS.LastChangeDate
FROM
  taProspect AS PS
    LEFT JOIN (
      SELECT
        ProspectID,
        SUM(QuotedAmount) AS QuotedAmount,
        SUM(IF((SalesPhaseID IS NULL) OR (SalesPhaseID < 5), 0, 1)) AS ClosedCount
      FROM
        taProspectProduct
      WHERE
        (ProspectID = @nProspectID)
      GROUP BY
        ProspectID
    ) AS X USING (ProspectID)
 WHERE
  (ProspectID = @nProspectID)
