Select to view content in your preferred language

arcpy.select invalid sql statement

2443
3
02-26-2013 11:00 AM
BobMCkay
Deactivated User
Hi

The following script is giving a syntax errror on the arcpy.Select line.
I've tried various combinations of Quotes but I still get the invalid sql statement.
Any ideas?

# Import arcpy module
import arcpy
# Local variables:
PropertyNew = "M:\\GIS\\KMZ Irrigation East\\PropertyNew.shp"
OwnerPropertyShp = "M:\\GIS\\KMZ Irrigation East\\OwnerProperty.shp"
# Process: Select   
arcpy.Select_analysis(PropertyNew, OwnerPropertyShp, "[PARCEL_SPI] = '2003\\PP2679'")

Traceback (most recent call last):
  File "M:\GIS\KMZ Irrigation East\owner.py", line 19, in <module>
    arcpy.Select_analysis(PropertyNew, OwnerPropertyShp, "[PARCEL_SPI] = '2003\\PP2679'")
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\analysis.py", line 88, in Select
    raise e
ExecuteError: ERROR 999999: Error executing function.
An invalid SQL statement was used.
An invalid SQL statement was used.
Failed to execute (Select).
Tags (2)
0 Kudos
3 Replies
MathewCoyle
Honored Contributor
You are using personal geodatabase syntax on a shapefile. Try this.

""""PARCEL_SPI" = '2003\PP2679'"""


If you are still having issues try making your selection manually in ArcMap using select by attributes and copy the syntax that works there.
0 Kudos
BobMCkay
Deactivated User
That worked fine. I thank you sincerely, but what does the deep imbedding in double quotes do? Can I also pass the string in as a Python argument i.e. how would I deal with all the quotes in a variable. Could I do something like
,""""&var1&''''''"). Once again many thanks
0 Kudos
MathewCoyle
Honored Contributor
The triple quotes ensure everything inside is a string so you don't have to use escape characters when you want to use multiple quotations inside your string. You can pass variables to it using standard string substitution just like any other string, though it wouldn't be necessary.
"""{0}""".format(some_variable)
0 Kudos