2

I'm trying to use an integer value in a WHERE clause (looking at an integer field).

expression = "'SERVICE' = 'Service' "
expression = expression + 'AND '
expression = expression + "'GPS_TIME_TOTAL' > " + "%d" % 10
arcpy.SelectLayerByAttribute_management(outServFCView,"NEW_SELECTION",expression)

This code (using the %d) gives me 'ExecuteError: ERROR 000358: Invalid expression'

When I use %s and '', it runs OK but doesn't give me any records because it's looking into a integer field to find a string.

'SERVICE' = 'Service' AND 'GPS_TIME_TOTAL' > '10'

Any ideas?

  • 3
    post your solution as an answer to your question(then mark it). so it can help people who faces the same problem. – Aragon Apr 24 '13 at 11:46
  • Aragon is suggesting that instead of editing your question with the solution, paste the solution into "Your Answer", then mark that answer as accepted. This way future readers will know what worked, and won't confuse the solution with the original question. Thanks. – user3461 Apr 24 '13 at 15:06
3

Try this

sql = '"SERVICE" = \'Service\' AND "GPS_TIME_TOTAL" > %d' % 10
|improve this answer|||||
0

Found a solution. I built it up in Arcmap and got the python snippit... turns out using docstring will work

expression = expression + '''"GPS_TIME_TOTAL" < 15'''
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.