Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use LIKE in expression

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
US
I want to evaluate a field in an expression. I want to say if it is LIKE something then make it something else. I am not able to just use LIKE in my formula. How is that done?

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Use Left() function if you want to compare the first characters from a string with another string.
if Left('abc', 2) = 'ab' then
true
else
false

-------------------------------------------------------------------------------------------------------------------------
"Now I can look at you in peace; I don't eat you any more." Franz Kafka, while admiring fish in an aquarium
 
Here is an example:

if {@formula} like "*ABC*"
then true
else false

Another example

if {@formula} like "A?C"
then true
else false

In the first case, the asterisk is for any number of characters, in the second, the question mark indicates one and only one character. You can use fields or formulas, with all the attendant precautions.

You can also use Instr in a similar fashion.

if {@formula} like "*ABC*"
then true
else false

becomes

if instr({@formula},"ABC",1)>0
then true
else false

Instr returns a numeric location in the string. Hence the >0 indicates anywhere. If you want to know if it were the first you'd make it

if instr({@formula},"ABC",1)=1
then true
else false

No reason not to use Like if you prefer it.


And of course in all of these cases you can remove the true false, like this:

{@formula} like "*ABC*"

because this returns a true or false and the if-then is implied. I included them above for clarity's sake. And you may want to return something other than true/false such as a string or a number, or the result of another equation.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top