Select to view content in your preferred language

Select from user input variable

2944
25
Jump to solution
09-10-2012 08:27 AM
NoahHuntington
Deactivated User
Please help.  Unable to make selection.

Here is what I have....

# Model selects parcel from user input import arcpy  # Assign variable to the feature class featureClass = "G:\\PRAD\\PRAD_v10.1.gdb\\tax_acct"  # Assign variable to users input input = arcpy.GetParameterAsText(0)  # Make a feature layer from feature class arcpy.MakeFeatureLayer_management(featureClass, "layer")       # Apply a selection to the feature layer  arcpy.SelectLayerByAttribute_management("layer", "NEW_SELECTION", '"'+str(input)+'"') 
Tags (2)
0 Kudos
25 Replies
MathewCoyle
Honored Contributor
Ok. I will see what I can do with that.  Thanks for all your help!


I made a slight addition to the loop to add the if/else to get the proper and statements added.
0 Kudos
NoahHuntington
Deactivated User
I made a slight addition to the loop to add the if/else to get the proper and statements added.


Is there a way of doing something similar and searching three fields with one input box?
0 Kudos
MathewCoyle
Honored Contributor
Is there a way of doing something similar and searching three fields with one input box?


Possibly, you would need to describe your schema and values more though or post examples of your data.
0 Kudos
NoahHuntington
Deactivated User
Possibly, you would need to describe your schema and values more though or post examples of your data.


[ATTACH=CONFIG]17604[/ATTACH]

I would like to be able to get same selection of first row by using either job_num or job_num2 using single input box.
0 Kudos
MathewCoyle
Honored Contributor
[ATTACH=CONFIG]17604[/ATTACH]

I would like to be able to get same selection of first row by using either job_num or job_num2 using single input box.


I'm not sure what you are doing since you will never be able to select one row with any query unless you reference a unique ID, which it seems neither job_num nor job_num2 are. If there are values that are the same between the two columns but do not match the same row this would be even more challenging to implement in a single parameter.

If there are no numbers that match between the columns and you just want a number inputted to return any result from those three columns that match, try this as your query.

query = "{1} = '{0}' or {2} = '{0}' or {3} = '{0}'".format(job_num, "Job_Num", "Job_Num2", "Job_Num3")
0 Kudos
NoahHuntington
Deactivated User
I'm not sure what you are doing since you will never be able to select one row with any query unless you reference a unique ID, which it seems neither job_num nor job_num2 are. If there are values that are the same between the two columns but do not match the same row this would be even more challenging to implement in a single parameter.

If there are no numbers that match between the columns and you just want a number inputted to return any result from those three columns that match, try this as your query.

query = "{1} = '{0}' or {2} = '{0}' or {3} = '{0}'".format(job_num, "Job_Num", "Job_Num2", "Job_Num3")


I am probably adding to the confusion here.  In the picture above I would like to be able to use either '976488' or '98770' in query parameter to select that top record.
0 Kudos