CREATE DEFINER=`root`@`localhost` PROCEDURE `GetClients`(
clientPIB NVARCHAR(50),
pageSize INT,
pageIndex INT)
BEGIN
DECLARE startIndex INT;
SET startIndex = pageSize * pageIndex;
SELECT Id, FirstName, LastName, MiddleName
FROM Client
WHERE
FirstName Like(CASE WHEN clientPIB IS NULL THEN FirstName ELSE '%' + clientPIB + '%' END) OR
LastName Like(CASE WHEN clientPIB IS NULL THEN LastName ELSE '%' + clientPIB + '%' END) OR
MiddleName Like(CASE WHEN clientPIB IS NULL THEN MiddleName ELSE '%' + clientPIB + '%' END)
LIMIT startIndex, pageSize;
END
答案 0 :(得分:0)
而不是'%' + clientPIB + '%'
使用concat('%', clientPIB, '%')
实际上,+符号保留用于算术运算。