Select to view content in your preferred language

Calculate Value Replace Expression

554
2
08-22-2011 04:55 AM
MatthiasAbele
Emerging Contributor
Hallo,

I'd like to iterate through a list of values. The values are used as field name inline variables and sql-expression for a select command.

To build the sql statement from the list, I use the calculate value function.
My list elements look like: !0?2,!0?4
I am trying to get the sql-statement by the following command in the calculate Value - tool:
"%Value%".replace("!",""vges>=").replace("?",".")


But I always get an error:

ERROR 000539: Error running expression: "!0?2".replace("!",""vges>=").replace("?",".") <type 'exceptions.SyntaxError'>: invalid syntax (<string>, line 1)
Failed to execute (Calculate Value).

What could be the reason?

Attached an overview from the modell builder.

Thanx,

Matthias
Tags (2)
0 Kudos
2 Replies
MarcNakleh
Regular Contributor
Hello there,

I don't know if the answer to this question is still relevant to you, but there are a couple of things that strike me as strange about your expression:

1) There seems to be an extra quotation mark in your first replace ""vges>=". Alternatively, if you wanted to keep the extra quotation mark, you would either need to escape it ("\"vges>=") or encapsulate the whole string in single quotes ('"vges>=')
2) The field placeholder for Python snippets is !FieldName! with no quotations around (or the value would be interpreted as a literal.)

Either of these could be giving an invalid syntax error. Given the above, I would write the expression as:
!Value!.replace('!', 'vges>=').replace('?', '.')

I hope this helps!
0 Kudos
MatthiasAbele
Emerging Contributor
Thanx, your points were right; that is the way I could fix the problem.

Matthias
0 Kudos