EDIT: Finally found a way around this..
expression = "[Route] = '" + route + "' AND [Trip] = " + str(trip) arcpy.MakeTableView_management(solutionTable, "solutionView", expression )
I tried str() before but used a semicolon instead of 'AND' to join them together.
Still, I'd be interested to know why the below didn't work
I'm trying to query a table by 'route' (a string) and 'trip' (a integer), but I can't for the life of me get it to work..
def getPropertyCounts(route, trip): countProps = 0 expression = "[Route] = '" + route + "' AND [Trip] = %d" % trip arcpy.MakeTableView_management(solutionTable, "solutionView", "'" + expression + "'") countProps = arcpy.GetCount_management("solutionView") print countProps return countProps
When I print out the SQL expression, it looks like it should work fine. But the 'countProps' variable just comes up with the total number in the table.
When I just do the 'route' expression on its own, it works fine.
Not sure if you need the 's either side of the expression but I've tried without, unsuccessfully.