I have this Feature Class to Feature Class script that creates a feature class of patient visits for each store for every month for every year it has been open. However, when I run the script it will create feature classes by month and year with the correct labels, for example (Jan2015_NWPatientVisits2000Gresham), but when I look at the attribute table it contains no data.
I'm sure I am missing something small, but I just can't seem to figure out what it is.
Here is my script:
import arcpy
# Set environment settings
arcpy.env.workspace = r"C:\arcGIS_Shared\Python\CenterHeatMaps.gdb"
#Declare variables
fc = 'Open_Store_Centers'
fields = ['USER_market_id','USER_Store_ID','USER_Store_Center_Name']
fieldname = 'USER_market_id'
#Define WHERE clause statement
whereclause = """{} = 2000""".format(arcpy.AddFieldDelimiters(fc, fieldname))
sqlclause = (None, 'Order By USER_market_id, USER_Store_ID')
# loop through months
years = [2015, 2016, 2017]
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
for year in years:
for month in months:
with arcpy.da.SearchCursor(in_table = fc, field_names = fields, where_clause=whereclause, sql_clause=(None, 'ORDER BY USER_market_id, USER_Store_ID')) as cursor:
#Loop through each row established in cursor
for row in (cursor):
# Set local variables for FeatureClasstoFeatureClass
inFeatures = "PatientVisitsGeocoded"
outLocation = r"C:\arcGIS_Shared\Python\CenterHeatMaps.gdb"
outFeatureClass = "{2}{3}_NWPatientVisits{0}{1}".format(row[0], row[2], month, year)
delimitedfield = arcpy.AddFieldDelimiters(arcpy.env.workspace,"USER_CenterID")
expression = delimitedfield + "= {0}".format(row[1]) + " AND USER_DOSYear = {0}".format(year) + " AND USER_DOSMonth = '{0}'".format(month)
# Execute FeatureClassToFeatureClass
arcpy.FeatureClassToFeatureClass_conversion(inFeatures, outLocation, outFeatureClass, expression)
#Print Results
print(row[2])
count = arcpy.GetMessageCount()
print (arcpy.GetMessage(count-1))
Select
existed. However, I think I'm close to getting this to work. I realized that CenterID and StoreID were really the same thing but had different data types so I changed them both into "Text". Now I'm getting an error saying the following is an invalid SQL statementexpression = """{0} = {1} AND USER_DOSMonth = '{2}' AND USER_DOSYear = {3}""".format(delimitedfield, row[1], month, year)