未按输入行执行搜索

时间:2016-06-18 10:17:31

标签: mysql

    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

表客户端有一个字段 enter image description here 当我没有指定搜索条件,那么名称或名称 - 一切都很好 enter image description here

但是从哪里开始搜索名称或返回任何名称 enter image description here

1 个答案:

答案 0 :(得分:0)

而不是'%' + clientPIB + '%'

使用concat('%', clientPIB, '%')

实际上,+符号保留用于算术运算。