Hi,
I want to subset my database and when I tried
arcpy.SelectLayerByAttribute_management ("OHlyr3", "NEW_SELECTION", " [SUBTYPECD]" LIKE \'%Overhead\' )
I was getting an error on the sql expression. Than I found out the field "SUBTYPECD" is really a domain.
What I need is to query against part of it's value like Overhead where I have "Single Phase Overhead" as a domain value It's coded number is 2 if that's easy.
Any ideas?
Solved! Go to Solution.
I found out the field "SUBTYPECD" is really a domain.
The field isn't a domain, it's a field that is controlled by a domain. What happens if you write your query like this:
select = 'SUBTYPECD = 2'
arcpy.SelectLayerByAttribute_management ("OHlyr3", "NEW_SELECTION", select)
I found out the field "SUBTYPECD" is really a domain.
The field isn't a domain, it's a field that is controlled by a domain. What happens if you write your query like this:
select = 'SUBTYPECD = 2'
arcpy.SelectLayerByAttribute_management ("OHlyr3", "NEW_SELECTION", select)
I started typing before you replied Joe, honest!
This works, it's the simple solution that I overlooked. Instead I tried 20 different ways screwing around with the quotes and backslashes that just confused me. Thanks.
Yep. 'Love me a good ol' over-thinking session. Then when it's over, simple wins!
What an interesting question, I was trying to wrap my head around that!
Can you just work out which domains contain 'Overhead'?
eg if overhead appears in coded value 2,4,9 and 10:
"[SUBTYPECD]" IN (2, 4 ,9, 10)
I also believe the query should be passed as a string in itself, ie:
query = ' "[SUBTYPECD]" IN (2, 4 ,9, 10) '
arcpy.SelectLayerByAttribute_management ("OHlyr3", "NEW_SELECTION", query )
hope this helps
The beauty of this forum!