Select to view content in your preferred language

Select Layer By Attribute Using Variable In ModelBuilder

192
3
08-01-2024 08:08 AM
AbiDhakal
Frequent Contributor

Hello GIS friends,

I'm using a ModelBuilder to select Multiple values from a layer and it is not working. It only works when I select a single value. What am I doing wrong please.

Select Layer By Attribute expression window:

AbiDhakal_3-1722524191459.png

Model: Please do not worry about the grey portion. That part is working fine. Instead, the part that is not grey is not working.

AbiDhakal_0-1722523636153.png

Geoprocessing:
In the window below marked in red, if I only put one value (SPB) then it will select, however if I put multiple values (SPB, EAB, etc.) as shown below it will not select. 

AbiDhakal_2-1722524068715.png

I've added a variable to the model that would allow me to put Multiple values.

AbiDhakal_4-1722524626931.png

Please help me.

Thank you,
Abi

 

 

 

0 Kudos
3 Replies
EdMorris
Esri Contributor

Hello!

Did you have any joy in finding a solution?

I have managed to use the Select Layer By Attributes tool in Model Builder using the AND operator to query a string and a numeric field, which I think is what you want to do.

I have assumed that your variable parameter YearParameter is numeric. Would that be correct?

My model does what you want to do.

EdMorris_0-1723220728201.png

 

It assumes the Gender variable parameter is querying a string attribute field (this would be the equivalent of your TypeParameter ) and so the variable  parameter datatype is set to String.

The Pupils variable parameter is querying a numeric attribute field (this would be the equivalent of your YearParameter) and so the variable parameter datatype is set to Long.

Notice my SQL Expression:

EdMorris_1-1723220786626.png

The Gender parameter is surrounded by %% signs and speech marks as you would expect, as it is querying the GENDER attribute field in my Schools dataset.

The Pupils parameter is surrounded by %% but it  IS NOT enclosed by speech marks as querying a numeric field. I think when you placed speech marks around your "%YearParameter%" you turned it into a string...?

So.... remove the speech marks around your YearParameter in the SQL Expression for the Select Layer By Attribute tool and change the data type of the YearParameter variable parameter to Long?

I hope this helps.

ed

0 Kudos
AbiDhakal
Frequent Contributor

Hey Ed,

Lol, it would've been a joy had I found a solution. Thank you for posting your response. I really appreciate it. 

I tried your syntax. Both my parameters are string, and the SQL Expression is not working. I do not know what I'm doing wrong.

Please advise.
Abi

0 Kudos
AbiDhakal
Frequent Contributor

@EdMorris 

Are you able to find out anything, Ed?

0 Kudos