Passing paramaters / variables thru Select Layer By Location

Discussion created by leftieant76 on Aug 18, 2012
Latest reply on Aug 19, 2012 by brucejr312
Good afternoon all

Having some issues with the Select By Location function returning an odd error message that I can't shake out.

I'm pretty confident it's falling over on the first half of the if..else command. This is in there to differentiate between features which need to be checked with a buffer distance and those that don't (this bit of code will be iterated through all the features in a dataset individually).

Code (or snippets of):

sqlquery = OIDFieldName + "=" + str(oid)
dataset_tocheck_lyr = arcpy.MakeFeatureLayer_management(dataset_tocheck, "dataset_tocheck_lyr", "\"sqlquery\"")
themelocation_lyr = arcpy.MakeFeatureLayer_management(themelocation, "themelocation_lyr") #create temp layer of theme location
bufferdist = str(int(overlayfeature.DIST)) + " Meters"
                if int(overlayfeature.DIST) == 0: 
                    arcpy.SelectLayerByLocation_management(themelocation_lyr, "INTERSECT", dataset_tocheck_lyr, "","NEW_SELECTION")
                    output_text.write("Buffer is zero, not factoring into SBL\n\n")
                    arcpy.SelectLayerByLocation_management(themelocation_lyr, "INTERSECT", dataset_tocheck_lyr, "\"bufferdist\"", "NEW_SELECTION")
                    output_text.write("Buffer is not zero, factoring additional string into SBL\n\n")


Traceback (most recent call last):
  File "C:\Python26\ArcGIS10.0\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript
    exec codeObject in __main__.__dict__
  File "U:\PythonValuesChecking\Python Scripts\ValuesChecker.py", line 74, in <module>
    arcpy.SelectLayerByLocation_management(themelocation_lyr, "INTERSECT", dataset_tocheck_lyr, "","NEW_SELECTION")
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4381, in SelectLayerByLocation
    raise e
ExecuteError: ERROR 999999: Error executing function.
An invalid SQL statement was used.
An invalid SQL statement was used.
An invalid SQL statement was used.
An invalid SQL statement was used.
Failed to execute (SelectLayerByLocation).

This has thrown a few other problems at me, which I have so far been able to solve, but this one has got me stuffed.

Any thoughts?