I am using ArcMap 10.2.2 and trying to make separate feature classes from a larger feature class using a field delimiter and SQL statement but am getting an error that the SQL statement is invalid. Here is the snippet of code I'm having a problem with:
# This script looks at a featureclass(FC)/service location(SL)
# and splits it by day for web service data preparation.
# In this manner, end users can toggle off and on days of service.
#import modules
import arcpy
import os
#create input FC/SL -- the mega FC/SL
inputFC = raw_input("Paste Route FC from ArcCatalog: ")
#set default geodatabase
arcpy.env.workspace = raw_input("Paste default file GDB from ArcCatalog: ")
#designate output location as a variable so it can be used in system path
#output filename
outLocation = arcpy.env.workspace
# Designate the type of fleet, service, commodity etc
fleetType = raw_input("Name of output (e.g. Residential_Garbage, NO SPACES!!!): ")
#make a copy of the input FC so nothing gets corrupted
arcpy.MakeFeatureLayer_management(inputFC, "Copy_inputFC")
dayList = []
while True:
day = raw_input("Type field delimiter and press enter. Type and enter 'Done' when finished: ")
if day.lower() == 'done':
break
dayList.append(day)
#Make multiple FCs based on route number
for day in dayList:
#Add field delimitters
delimFld = arcpy.AddFieldDelimiters("Copy_inputFC", "Exist_Partition")
print "step1"
if day == '1':
dayName = 'Monday'
elif day == '2':
dayName = 'Tuesday'
elif day == '3':
dayName = 'Wednesday'
elif day == '4':
dayName = 'Thursday'
else:
dayName = 'Friday'
#Get output name
outName = "{0}{1}{2}".format(fleetType,"_",dayName)
outFC = os.path.join(outLocation, outName)
print "step2", outFC
#If routes are numbers:
try:
sql = "{0}={1}".format(delimFld, day)
arcpy.Select_analysis("Copy_inputFC", outFC, sql)
#If routes are strings
except:
sql = "{0} = '{1}'".format(delimFld, day)
arcpy.Select_analysis("Copy_inputFC", outFC, sql)
print outName
print "Finished"
This is what the error is saying:
ExecuteError: ERROR 000358: Invalid expression "Exist_Partition" = '1'
Failed to execute (Select).
However, if I do the SQL statement in ArcMap it appears to be fine: