Click here to Skip to main content
15,913,130 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am writing a query with like operator in where clause. i need different like operator in where clause.

suppose UniversityName Column contain a string '
UU3-UU8-UU14-UU18-UU23-UU24-UU45-UU74
'

i don't want to use OR operator. so i want to use In Operator. but it not working.

What I have tried:

Select * From MasterCustomer where UniversityName Like'%UU1%'


Select * From MasterCustomer where UniversityName In (Like'UU1', Like'UU1-%', Like'%-UU1', Like'%-UU1-%')
Posted
Updated 6-Mar-17 2:45am
Comments
Bryian Tan 6-Mar-17 9:55am    
What wrong with Like'%UU1%'?

1 solution

It depends what you are trying to do: the second "what I have tried" syntax will not work at all (and none of the LIKE sequences would match your example).

But the first one:
SQL
...WHERE UniversityName LIKE '%UU1%'

should work, as it will match your example several times: UU14 and UU18. The "%" is a wildcard, meaning "any number of any characters", similar to the "*" in windows filenames, so '%UU1% matches any input string that contains UU1 in any location.

I suspect that you need to take another look at your data, as I suspect the UniversityName column does not contain "UU3-UU8-UU14-UU18-UU23-UU24-UU45-UU74" (or is has completely the wrong column name for the content it does have).
 
Share this answer
 

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