TransWikia.com

Selecting attributes that contain "%"-symbol in Field Calculator

Geographic Information Systems Asked by xxxD on February 28, 2021

I have a Text field and it contains values that have a "%"-symbol and "°"-symbol.
Example:

1.2% 3.2° 2.3% -1.2°

I don’t know how to select just the values that have the "%"-symbol because Field Calculator thinks its a Wild Card. Any ideas?

One Answer

From the last answer to How do I escape a percentage sign in T-SQL? this is working with my data that is in a file geodatabase:

textfield LIKE '%|%%' ESCAPE '|'

The query might be different depending on your data source.

You can use python with da.SearchCursor to look for %-signs and select by objectid of the rows matching:

import arcpy
layer = 'ak_riks'
field_to_search_in = 'textfield'
search_for = '%'

oidfield = arcpy.Describe(layer).OIDFieldName
oids_to_select = tuple([oid for oid, phrase in arcpy.da.SearchCursor(layer, ['OID@', field_to_search_in]) if search_for in phrase])

sql = """{0} IN{1}""".format(oidfield, oids_to_select)
arcpy.SelectLayerByAttribute_management(in_layer_or_view=layer, where_clause=sql)

enter image description here

Answered by BERA on February 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP