1

I am aware that problems like mine exist (example) but I think, this is slightly different.

I want to use MultiValue to let the user choose various inputs at the same time. The problem is, that it's only possible to use MultiValue in combination with String and not, how I would need it, as SQL.

Because I'am trying to create a toolbox, these are my properties (and on the right side my MultiValue-Field in the Toolbox:

Toolbox-Properties

I did it like this:

multival = arcpy.GetParameterAsText(1)
vals = string.split(multival, ";")
where_clause = string.join(vals, "+")

My problem is, that my output now has quotation marks and is not combined to one big SQL-expression.

The expression I am aiming for would look like this:

"Name = 'Store_1' OR Name = 'Store_2' OR Name = 'Store_5' OR Name = 'Store_8'"

But right now it looks like this:

'Name = 'Store_2''+'OR Name = 'Store_3''+'OR Name = 'Store_4''+'OR Name = 'Store_5''

Is there a way to have the outputs without quotations marks and added to one expression?

  • 1
    Would it also be possbile to choose values with: "Name" in ('Store_1','Store_2', etc.) ? – GISbert Feb 20 '17 at 14:14
2

Your comment on using the IN is a good way to go; makes the code much simpler.

multival = arcpy.GetParameterAsText(1)  # 'Store_1;Store_2;Store_3'
vals = multival.split(";")

where_stub = """"NAME" IN ({})"""
stores = ','.join(["'{}'".format(x) for x in vals])
where = where_stub.format(stores)

You can combine some of those lines, if you'd like.

EDIT: I just noticed your screenshot has the "OR NAME =" in there. There's no need. Just have the list of values. For example:

  • Store_1
  • Store_2
  • etc
  • Thank you very much! Your code works finde, my output is "NAME" IN ('Store_1','Store_2','Store_3'). But now when I run the Select-Tool (arcpy.Select_analysis(Input, Output, where) the shapefile I get is empty. Any Ideas? – GISbert Feb 21 '17 at 8:45
  • It is probably best to ask a new question with your code and data spelled out. – Richard Morgan Feb 21 '17 at 9:32
  • Yes, you are right. I solved it now using a for-loop. Do you think I should post it as a comment? – GISbert Feb 21 '17 at 10:07
  • Comments are usually for short ideas. You can also update your original question to show a solution, etc. – Richard Morgan Feb 21 '17 at 13:38
  • Me again, your solution worked totally fine, I just messed something up in the toolbox properties. Tanks again! – GISbert Feb 21 '17 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.