I have a script that works great with selecting dates greater than "my From date" but I can't get the code to work when I want to add a less than to the sql where clause (a to date).
I had add the {0}'".format to get the original where clause to work. But can't figure out how to add the second date. I have tried AND and BETWEEN with no luck.
Any idea how to do this?
I'm stuck!
This is the code that works perfectly for the single from date:
where_time_period = "dtrepor > '{0}'".format(object_FromDate)
table_out = os.path.join(output_gdb, "MyRecords")
if arcpy.Exists(table_out):
arcpy.Delete_management(table_out)
arcpy.MakeQueryTable_management(incident_table, table_out, where_clause =
where_time_period)
update: If I run the code with just the where_time begin it works perfectly. If I try to add where_time_end it gives me all the records. I just tried to change the where_clause to this
where_time_begin = "dtrepor > '{0}'".format(object_FromDate) where_time_end =
"dtrepor < '{0}'".format(object_ToDate)
arcpy.MakeQueryTable_management(incident_table, table_out, where_clause =
where_time_begin and where_time_end)
instead of giving me less record it
It returns all the records –
If I try where_clause with "AND" or Between, my code won't run? where_time_begin + "AND" + where_time_end
Here's a bit more of the code
#define workspace#
arcpy.env.workspace = r"C:\Users\mandrews\Documents\ArcGIS\Default.gdb"
dbo_path=r"C:\Users\mandrews\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\Spillman_rep_OLE_D.odc"
sde_path = "C:\Users\mandrews\AppData\Roaming\ESRI\Desktop10.5\ArcCatalog\RepSpillman.sde"
#mxd_all_incidents = arcpy.mapping.MapDocument(r"C:\AlexaWetmore\monthlyAll.mxd")
mxd_all_incidents = arcpy.mapping.MapDocument(r"C:\Users\mandrews\Documents\monthlyIncidentMaps\monthlyAll.mxd")
output_dir = (r"C:\Users\mandrews\Documents\monthlyIncidentMaps")
output_gdb = (r"C:\Users\mandrews\Documents\monthlyIncidentMaps\monthlyIncidents.gdb")
#call addr temp
addr_temp = os.path.join(r"C:\Users\mandrews\Documents\ArcGIS\Default.gdb", "AdderTemp")
#copy lwmain table with this sql query for from date
incident_table = os.path.join(dbo_path,"dbo.lwmain")
offense_table = os.path.join(dbo_path,"dbo.lwoffs")
where_time_begin = "dtrepor > '{0}'".format(object_FromDate)
where_time_end = "dtrepor < '{0}'".format(object_ToDate)
table_out = os.path.join(output_gdb, "MyRecords")
if arcpy.Exists(table_out):
arcpy.Delete_management(table_out)
arcpy.MakeQueryTable_management(incident_table, table_out, where_clause = where_time_begin + "AND" + where_time_end)
#show count of records selected
results = arcpy.GetCount_management(table_out)
count = int(results.getOutput(0))
print (count)
and
syntax appears to be in error, thought it's difficult to tell. You should probably include the between usage in the body as well.