Field name in-line variable substitution in ModelBuilder SQL query

2861
2
11-16-2012 08:48 AM
PaulFiner
New Contributor II
I've created a multivalue list of table field names by calling a python script in ModelBuilder. I'd like to iterate through the list of field names and create SQL queries for the "Select Layer by Attribute" tool. I'd also like to use the field name as an in-line variable in the query. I know how to use a value variable when constructing an SQL query (ex. "FIELDNAME" = '%variable%') but not with a field name. Is it possible?

Thanks,
Paul
0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor
Is it possible?


Sure is. Two ideas to help you along:

1) Use the Iterate Value tool to iterate the multivalue
2) Use Calculate Value to create the SQL expression as a string and set its output as type "SQL Expression"
0 Kudos
EllenTejan
New Contributor
How did you do it? We are trying to figure out the same thing, but are so new to python that we dont even know how to start.

We are trying to:
Bring in a table and feature class and join them (easily done, not in question)
Then calculate attributes in the feature class based on values in the joined table (mostly easily done).
BUT I want to allow for error on join table field names. So I would like to have them identify each field as parameterized values up front, then use inline variable subsitution in the calculation arguments to specify those fields. I would like for the field varable prompts to provide a list of fields from the joined table to choose from. Thats the part I 'm having trouble with.

Ellen
0 Kudos