Does anyone know how to use a wild card if then statement in field calculator?

1541
3
Jump to solution
05-05-2017 10:08 AM
DanCrawford
New Contributor

I'm trying to setup a simple if then statement that uses a wildcard:

If [SPECIES_CD_2] = "B" Then              ** this statement works but

If [SPECIES_CD_2] LIKE "B*" Then       ** this statement doesn't

I've tried substituting %, #, & for the asterisk but I keep getting an error (sub or function not defined)

Help!!!

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

When working in the field calculator, you are either using VBScript or Python, I strongly recommend Python.  The LIKE operator you are attempting to use is an SQL function.  Python does not have a LIKE string function and I don't believe VBScript does either.

Your syntax indicates you are using VBScript.  I believe If LEFT([SPECIES_CD_2],1) = "B" should mimic the LIKE statement you have provided.

View solution in original post

3 Replies
JoshuaBixby
MVP Esteemed Contributor

When working in the field calculator, you are either using VBScript or Python, I strongly recommend Python.  The LIKE operator you are attempting to use is an SQL function.  Python does not have a LIKE string function and I don't believe VBScript does either.

Your syntax indicates you are using VBScript.  I believe If LEFT([SPECIES_CD_2],1) = "B" should mimic the LIKE statement you have provided.

DanCrawford
New Contributor

Quick testing seems to confirm that what you suggest works!

Thank-you Joshua!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If my, or any other, response answers your question, please mark it Correct so others know you already have a workable solution.

0 Kudos