Modulo operator in SQL query not working for labels in Pro 2.3.1?

1748
3
03-13-2019 02:45 PM
TonyGrossman1
New Contributor II

I'm trying to add a custom SQL query to my labeling class and it doesn't like the modulo operator (%). It works in the definition query for the layer, but when I try to use it for a labeling class it doesn't like it. The name of the field I'm using in the query is "MRL_MEAS", and the query I'm trying to use is "MRL_MEAS % 1 = 0", because I want to only label the numbers divisible by 1. When I click the green check mark to validate it, it validates. But when I click "Apply", it says "The SQL expression has invalid syntax". This query should work. Again, it works in the definition query for the layer. This just seems to be a bug with the labeling classes. Has anyone else experienced this or know if I'm doing something wrong?

ArcGIS Ideas‌ 

0 Kudos
3 Replies
ThomasColson
MVP Frequent Contributor

So [OBJECTID] % 4 = 0, for example, works in SQL Management studio queries, but not in Arc or Pro 2.3.1, in def query or label query. Not sure if this is an ESRI "by design" thing.

0 Kudos
samhooper
New Contributor II

This topic is quite old, but I found that the modulo operator still does not work in label expressions or definition queries. However, in case anyone comes across this from an internet search, the MOD() function does work for this purpose. So something like MOD(field_name, 10) = 0 should work in place of field_name % 10 = 0. You might have to do MOD(CAST(field_name AS INT), 10) = 0 depending on your field's data type. 

PLadd
by
Occasional Contributor III

Thanks for including this: MOD(CAST(field_name AS INT), 10) = 0  It made me realize my data was in string format.

0 Kudos