SELECT * 
FROM App.PrecheckDetails 
WHERE IsComplete = 0 AND 
(CASE WHEN ISNULL(@SearchText, '') <> '' THEN 
       CASE 
              WHEN ApplicantName LIKE '%' + @SearchText + '%' THEN 1 
              WHEN OLPermitNumber LIKE '%' + @SearchText + '%' THEN 1
              WHEN IDNumber LIKE '%' + @SearchText + '%' THEN 1
              WHEN ChassisNumber LIKE '%' + @SearchText + '%' THEN 1
              WHEN VehicleRegistrationNumber LIKE '%' + @SearchText + '%' THEN 1
              ELSE 0
       END
       ELSE 1
END) = 1 AND
(
	CASE WHEN ISNULL(@ApplicantName, '') <> ''
		THEN CASE WHEN ApplicantName LIKE '%' + @ApplicantName + '%' THEN 1 ELSE 0 END
		ELSE 1
	END
) = 1 AND
(
	CASE WHEN ISNULL(@OLPermitNumber, '') <> ''
		THEN CASE WHEN OLPermitNumber LIKE '%' + @OLPermitNumber + '%' THEN 1 ELSE 0 END
		ELSE 1
	END
) = 1
AND
(
	CASE WHEN ISNULL(@IDNumber, '') <> ''
		THEN CASE WHEN IDNumber LIKE '%' + @IDNumber + '%' THEN 1 ELSE 0 END
		ELSE 1
	END
) = 1
AND
(
	CASE WHEN ISNULL(@ChassisNumber, '') <> ''
		THEN CASE WHEN ChassisNumber LIKE '%' + @ChassisNumber + '%' THEN 1 ELSE 0 END
		ELSE 1
	END
) = 1
AND
(
	CASE WHEN ISNULL(@VehicleRegistrationNumber, '') <> ''
		THEN CASE WHEN VehicleRegistrationNumber LIKE '%' + @VehicleRegistrationNumber + '%' THEN 1 ELSE 0 END
		ELSE 1
	END
) = 1
ORDER BY ApplicantName ASC 