Click here to Skip to main content
15,040,212 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Is there an alternative for LIKE that returns all the records when the given value is an empty string? Thanks.
Thanks7872 1-Sep-14 10:20am
No. That you have to handle somewhere. Like takes something and returns result similar to that one. You have to check some condition that if the passed parameter is blank get all the results.
Doughnatch 1-Sep-14 10:25am
I have 3 where condition in my query. I'm thinking of doing this:

WHERE (@parameter IS NULL OR NAME = @parameter) AND . . . .

Would this be acceptable? Do I need to enclose it in parenthesis?
Ashi0891 1-Sep-14 14:26pm
I guess you should better use it like
where ...... AND (name='' OR name=@parameter); and this should work.
Herman<T>.Instance 2-Sep-14 5:27am
I don't think so Tim! (famous words by the neighbour of Tim the Toolman;) )
When you do not pass the parameter it is NULL.


Try this...

Select * from yourTable where name = case when isnull(@para,'') ='' Then name else @para end

Hope this will help you.

You don't need the LIKE operator: you may directly use the = operator, e.g.
select * from mytable where name=''

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900