SUBSTRING SQL Expression

1628
3
Jump to solution
06-11-2014 11:24 AM
ToddCalico
New Contributor
Not having much experience in SQL or Python, I'm trying to take a shot at labeling a field using a SUBSTRING expression to return only the first 6 characters of a field.

The field is [SITE_ADDRE]

My expression looks like this:
SUBSTRING ([SITE_ADDRE] FROM 1 FOR 6)

I'm getting an error message so I know this is incorrect.

Any suggestions would be much appreciated.
0 Kudos
1 Solution

Accepted Solutions
IanMurray
Frequent Contributor
I don't think the label expressions take SQL expressions, only Jscript, python, and VBscript

For what you want you can use python and check advanced and put in this.

def FindLabel ( [[SITE_ADDRE] ):   return [SITE_ADDRE][0:6] 

The [0:6] is an index which return the the values of the string values in your field, from the first(python is zero indexed so first thing is 0) up to 6, but not including it. 

Should return the first 6 characters of your field value.

View solution in original post

0 Kudos
3 Replies
IanMurray
Frequent Contributor
I don't think the label expressions take SQL expressions, only Jscript, python, and VBscript

For what you want you can use python and check advanced and put in this.

def FindLabel ( [[SITE_ADDRE] ):   return [SITE_ADDRE][0:6] 

The [0:6] is an index which return the the values of the string values in your field, from the first(python is zero indexed so first thing is 0) up to 6, but not including it. 

Should return the first 6 characters of your field value.
0 Kudos
ToddCalico
New Contributor
Great thank you so much!!!
0 Kudos
IanMurray
Frequent Contributor
Actually, we have had alot of threads about how to format labels with python(and other means).  Always be sure to check the forums for similar posts, before starting a new one.
0 Kudos