Using .format in arcpy.SelectByAttributes Where Clause

Discussion created by BrokenLegMike on Apr 30, 2014
I am trying to pass an integer variable into the where clause of the arcpy.SelectByAttribute tool on an sde feature class to select a record from a "Long" field type.

siteNumber = 324850
SQL_Query = 'NUMBER_ID = {0}'.format(siteNumber)
arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION", SQL_Query)

This does not return any selected records.

If I hard code the query in:

arcpy.SelectLayerByAttribute_management("lyr2", "NEW_SELECTION", 'NUMBER_ID = 391530')

Then it will work.

When I print out my SQL_Query variable, I get

NUMBER_ID = 324850

I've tried:

SQL_Query = "\"NUMBER_ID\" = {0}".format(siteNumber)
SQL_Query = "\"NUMBER_ID\" = '{0}'".format(siteNumber)
SQL_Query = '[NUMBER_ID] = {0}'.format(siteNumber)

and a few other methods, and I still can't get it to return a selected record.