I have a Stored Proc that searches through records.
The problem is that some search criteria that come from the user interface may be an empty string. Thus, when criteria are not specified, the LIKE operator becomes redundant.
How can I efficiently perform this search or sql server? Or does he optimize the LIKE query ('%%'), since that means there is nothing to compare?
The stored process is as follows:
ALTER PROC [FRA].[MCC_SEARCH]
@MCC_Code varchar(4),
@MCC_Desc nvarchar(50),
@Detail nvarchar(50)
AS
BEGIN
SELECT
MCC_Code,
MCC_Desc,
CreateDate,
CreatingUser
FROM
FRA.MCC (NOLOCK)
WHERE
MCC_Code LIKE ('%' + @MCC_Code + '%')
AND MCC_Desc LIKE ('%' + @MCC_Desc + '%')
AND Detail LIKE ('%' + @Detail + '%')
ORDER BY MCC_Code
END
source
share