Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
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
    
OK - it says I can accept my own answer in 2 days –  Mike Apr 24 '13 at 16:06
add comment

2 Answers

Try this

sql = '"SERVICE" = \'Service\' AND "GPS_TIME_TOTAL" > %d' % 10
share|improve this answer
add comment
up vote 0 down vote accepted

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'''
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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