AnsweredAssumed Answered

SQL queries in label expressions

Question asked by jeffthomas on Feb 10, 2015

I currently have several label classes in a layer that are separated using SQL queries. However, many of these label classes are using the same symbol and placement properties; it's only the label expression that actually differs. Therefore, it seems logical to combine all features sharing symbology and placement into a single label class and then break out the different label expressions using conditionals. But I'm not sure how to translate my SQL queries into conditional statements. Or, preferably, somehow use the SQL query as a single conditional statement leading to each returned expression.

 

Here is an example of a SQL query I'm using:

 

structureNumber NOT LIKE 'NEW%' AND (structureNumber NOT LIKE '2[1-9][0-9][0-9]%' OR   structureNumber LIKE '260[0-579]%' OR   structureNumber LIKE '261[1357]%' OR   structureNumber = '2629' OR  structureNumber = '2800') AND  (structureNumber NOT LIKE '[3-7][0-9][0-9][0-9]%' OR   structureNumber LIKE '54[0-9][0-9]%' OR   structureNumber LIKE '6498%' OR   structureNumber = '7400') AND (structureNumber NOT LIKE 'AS1[0-3][0-9][0-9]%' OR   structureNumber = 'AS1000') AND  structureNumber NOT LIKE 'AS45[0-9][0-9]%' AND  structureNumber NOT LIKE 'AS60[0-9][0-9]%' AND structureNumber NOT LIKE 'KX6[6-9][0-9][0-9]%' AND (structureNumber NOT LIKE 'LCH4[0-9][0-9][0-9]%' OR   structureNumber LIKE 'LCH404[12]' OR  structureNumber LIKE 'LCH40[0-4][0-9]%') AND structureNumber NOT LIKE 'PP2[0-9][0-9][0-9]' AND  structureNumber NOT LIKE 'TT[389][0-9][0-9]' AND  structureNumber NOT LIKE 'TT[389][0-9][0-9][A-Z]' AND  structureNumber NOT LIKE 'TT[1-6][0-9][0-9][0-9]%'

 

And the label expression I'd like it to return:

 

def FindLabel ( [structureNumber] ):
   s = [structureNumber]
   s = s[-2:]
   return s

 

Any help you can provide for translating this into a conditional Python label expression would much appreciated! Thanks.

Outcomes