[SOLVED] Creating a minimum character requirement for a variable

Hi guys,

I'm curious if this is even possible. I'm trying to create a variable that lets user's search their own entry but I want the entry to be at least 3 or 4 characters long

select
user,
email
from emails
where email like CONCAT('%',{{Email}},'%')
Limit 1000

The issue with the code above is that, if the user enters 'T' every single email with the letter T in it will appear, I'm trying to avoid that.

Anyone have any ideas?

This works in SQL Server (easy to change for your query):

IF len({{search}}) > 3
select p.CustomerID, ContactLastName, ContactFirstName
 from Customer p 
where p.ContactLastName like CONCAT('%',{{search}},'%')
ELSE select 0, 'Too', 'Short';
3 Likes

Just came back to update what wound up working for me. (Thanks Andrew!)

If length({{search}}) > 3 then
select p.CustomerID, ContactLastName, ContactFirstName
from Customer p  
where p.ContactLastName like concat('%',{{search}},'%')
else
select concat('Please user more than 4 characters');
end if
;
2 Likes