I have the following code which I'm trying to get to select a row by an input task number. It gives me an error, saying that I have an invalid sql clause. However, looking at the error message, I can't see what's invalid.
import arcpy, os
from arcpy import env
task = arcpy.GetParameterAsText(0)
expression = "Task =" + " '" + task +"'"
base_arpx = arcpy.mp.ArcGISProject(r"\\Projects_3\Fig_2_Pro.aprx")
rows = arcpy.da.SearchCursor(r"\\Projects_3\location.gdb\Task_Project_Name_1",
"Task; Name; shp_project_points; shp_buffer; workspace;", where_clause=expression)
Here is the error:
File "<string>", line 8, in <module>
RuntimeError: An invalid SQL statement was used. [SELECT OBJECTID,Task; Name; shp_project_points; shp_buffer; workspace; FROM Task_Project_Name_1 WHERE Task = '590']
You use a comma after the first attribute field in the SQL query (OBJECTID) but then you switch to semi-colons. Try using all commas in your attribute field list inside the SQL query string.
It isn't just a comma or semicolon issue, the SearchCursor takes a list of strings, not a string of delimited fields.
Assuming "Task", "Name", "shp_project_points", "shp_buffer", "workspace" are all fields in your featureclass. As @JoshuaBixby notes, this parameter needs to be a list of field names, not a single string.
Change
"Task; Name; shp_project_points; shp_buffer; workspace;"
To
["Task", "Name", "shp_project_points", "shp_buffer", "workspace"]