SUBTYPECD=1 AND SERIESNAME NOT LIKE '%-%' AND OPERATIONALSTATUS IS NULL OR SUBTYPECD=1 AND SERIESNAME NOT LIKE '%-%' AND OPERATIONALSTATUS = 976
The above is my def query in ArcMap against ArcSDE 9.3.1 on oracle 9i with python 2.5. I want to be using the gp.makefeaturelayer with the sql parameter filled in with a rendition of the above.
ps I started to ask this question because it seemed daunting and I am in a crunch..then figured it out so I thought I'd finish the post for those to come.
-
and I welcome any critic of my sql..thanks community!Justin– Justin2011年05月24日 17:02:12 +00:00Commented May 24, 2011 at 17:02
-
1SUBTYPECD=1 AND SERIESNAME NOT LIKE '%-%' AND OPERATIONALSTATUS IN (NULL, 976)Brad Nesom– Brad Nesom2011年05月24日 18:26:02 +00:00Commented May 24, 2011 at 18:26
-
1@Brad, this didn't seem to work..I think..because, as I found out today, querying for NULL requires an IS operator and not and = which I assume is being replicated in the IN operator. This may be because oracle. Thanks anyways..Justin– Justin2011年05月24日 23:34:52 +00:00Commented May 24, 2011 at 23:34
3 Answers 3
Python allows you to use either single or double quotes for strings, so you can embed one within the other:
"embedding a 'single quote' in double quotes"
'embedding a "double quote" in single quotes'
So you could have gotten away with skipping all those concatenations, just using:
"SERIESNAME NOT LIKE '%-%' AND SUBTYPECD=1 AND OPERATIONALSTATUS IS NULL OR SUBTYPECD=1 AND SERIESNAME NOT LIKE '%-%' AND OPERATIONALSTATUS=976"
"SERIESNAME NOT LIKE" + "'" + "%-%" + "'" + "AND SUBTYPECD=1 AND OPERATIONALSTATUS IS NULL OR SUBTYPECD=1 AND SERIESNAME NOT LIKE" + "'" + "%-%" + "'" + " AND OPERATIONALSTATUS=976"
I can't confirm this for ArcMap 9.3 (the documentation makes no mention of it), but in ArcMap 10, you can embed an entire argument in triple quotes to avoid issues with concatenation and escape characters.
An example from the Make Feature Layer Tool:
Or you could enclose the entire string in triple quotes without escaping:
""" "CITY_NAME" = 'Chicago' """
-
That's actually just another Python convention. Triple-quoted strings can span newlines and can contain both single and double quotes without escaping them.jburka– jburka2011年05月25日 17:13:45 +00:00Commented May 25, 2011 at 17:13
-
I've never seen it used in Python aside from documentation, though. It makes me curious as to whether it's lack of mention in the 9.3 help indicates it will not function correctly.Nathanus– Nathanus2011年05月25日 18:12:27 +00:00Commented May 25, 2011 at 18:12
Explore related questions
See similar questions with these tags.