Select to view content in your preferred language

Select by Attribute using variable in Model Builder

3793
4
Jump to solution
12-16-2022 03:54 PM
DavidDurst
Occasional Contributor

I'm very new at Model Builder and am trying to make a tool that selects features by attribute, with an input variable as part of the SQL query.

I have used the SQL expression MOD(Elevation,10)=0, for instance to only display elevation contour lines every 10 units out of a dataset that has a more dense spacing (say 1 unit). This works great when using the Select by Attribute tool and setting a definition query, but in this case, I need an input parameter in my model instead of a hard-coded 10 units.

Here is an example of what I'm trying to do:

DavidDurst_0-1671234503583.png

When I draw my line from Supplementary Interval to Select Layer by Attribute, the entire model after Input Feature Class gets greyed out:

DavidDurst_1-1671234592118.png

How can I specify the second integer parameter of the MOD() function so that I can do my selections? Any help would be appreciated.

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Would something like this work for you? Right click on Select Layer by Attribute  then Create Variable from Parameter then Expression. The user will be prompted to enter a value:

SHartholt_0-1671560043412.png

I would also suggest reading up on inline variable substitutions: Inline variable substitution—ArcGIS Pro | Documentation

 

View solution in original post

0 Kudos
4 Replies
by Anonymous User
Not applicable

Have you tried to run your model from the toolbox? Although it looks like the model has failed, I think it may still run once you add a value in as a parameter.

0 Kudos
DavidDurst
Occasional Contributor

I have not tried to run the model yet. Part of the reason is that I'm also unsure how to reference the input parameter in my SQL query. Can you explain that to me? Is it simply MOD(ELEVATION,SupplementaryInterval)=0 ? I'm not real well versed in SQL either.

For some context, the part shown is the first in a series of select using a given parameter, run field calculator, rinse and repeat 3-4 times. My goal is to have attributes in a field that specify whether the contours are major, intermediate, minor, or supplementary (will make filtering contours and symbology much faster). As I have it set up now, each one of those requires a separate selection by parameter.

0 Kudos
by Anonymous User
Not applicable

Would something like this work for you? Right click on Select Layer by Attribute  then Create Variable from Parameter then Expression. The user will be prompted to enter a value:

SHartholt_0-1671560043412.png

I would also suggest reading up on inline variable substitutions: Inline variable substitution—ArcGIS Pro | Documentation

 

0 Kudos
DavidDurst
Occasional Contributor

Yes, that did it, more or less. It prompts for the SQL query for each selection, but I can live with that for now. I'd like to read up on inline variable substitution so the various inputs are just numbers rather than expressions, but this got the job done. Thanks a bunch!

DavidDurst_0-1671754516577.png

 

0 Kudos