I currently have two sql's queries in a script, is there a way to combine SQL1 & SQL2 so I am not doing two separate queries?
table1 = r"C:\Temp\Table"
from_date = DT.date.today() - DT.timedelta(days=730)
SQL1 = "AppSubmitted >= DATE '{}'".format(from_date.strftime('%Y-%m-%d')) #'%Y-%m-%d %H:%M:%S'
SQL2 = "PNum LIKE 'RZ%' OR PNum LIKE 'OR%' OR PNum LIKE 'CR%'"
arcpy.MakeTableView_management(table1, 'tableview', SQL) #Include SQL2
Solved! Go to Solution.
You can use the AND or OR operator to combine the SQL statements depending on what you're trying to achieve.
sql_expression = "({}) and ({})".format(SQL1, SQL2)
or
sql_expression = "({}) or ({})".format(SQL1, SQL2)
You can use the AND or OR operator to combine the SQL statements depending on what you're trying to achieve.
sql_expression = "({}) and ({})".format(SQL1, SQL2)
or
sql_expression = "({}) or ({})".format(SQL1, SQL2)
Sweet, thank you.
SQL1 = "AppSubmitted >= DATE '{}'".format(from_date.strftime('%Y-%m-%d')) #'%Y-%m-%d %H:%M:%S'
SQL2 = "PNum LIKE 'RZ%' OR PNum LIKE 'OR%' OR PNum LIKE 'CR%'"
sql_expression = "({}) and ({})".format(SQL1, SQL2)
arcpy.TableToTable_conversion(table1, workspace,'tableTEST', sql_expression)