Good day. Faced with an incomprehensible error in writing the repository for selecting all clients that are assigned to the specified addresses.
CREATE DEFINER=`grasa_db`@`%` PROCEDURE `GetClients`( likeParam NVARCHAR(50), pageSizeParam INT, pageIndexParam INT, idPersonnelParam CHAR(36)) BEGIN DECLARE startIndex INT; SET startIndex = pageSizeParam * pageIndexParam; SELECT Id, FirstName, LastName, MiddleName FROM client WHERE (client.IdAddress IN (SELECT personneladdress.IdAddress FROM personneladdress WHERE personneladdress.IdPersonnel = idPersonnelParam) AND FirstName Like(CASE WHEN likeParam IS NULL THEN client.FirstName ELSE concat('%', likeParam, '%') END) OR LastName Like(CASE WHEN likeParam IS NULL THEN client.LastName ELSE concat('%', likeParam, '%') END) OR MiddleName Like(CASE WHEN likeParam IS NULL THEN client.MiddleName ELSE concat('%', likeParam, '%') END)) LIMIT startIndex, pageSizeParam; END
So here is the essence: by transferring the staff ID, I get a list of addresses for which it is assigned. Next, select clients that are assigned to any of the selected address. Everything seems to be working, but when a check for a search by name is added, all clients are displayed at all addresses, even for those who are not assigned to the specified personnel.