arcpy.Select_analysis - Multiple conditions for where_clause

1022
3
Jump to solution
11-05-2019 04:51 PM
RayHardjadinata1
New Contributor

Hello,

What is the proper syntax for where_clause when I have multiple conditions?

This is what I got when I exported from my model builder:

arcpy.Select_analysis(in_features = Pipe_Table__WGS_PIPE_,
                                    out_feature_class = WGS_PIPE,
                                    where_clause = "PIPE_DIAMETER <= 20 And SYS_ZONE <> 0 And OWNER = 'WDD' And USE_TYPE IN ('DIST', 'TRUNK', 'LSLATERAL', 'MANIFOLD') "

                                     )

The above returns me an error.

However, if I just do one condition such as the following below, it works... 

arcpy.Select_analysis(in_features = Pipe_Table__WGS_PIPE_, 
                                    out_feature_class = WGS_PIPE, 
                                    where_clause = "PIPE_DIAMETER <= 20" )

Can anyone please help? Thanks! 

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

I guess 'And' is somehow correct , but I got failures without specifying a workspace first OR the full path to the source and destinations

arcpy.analysis.Select(r"C:\Git_Dan\npgeom\npgeom.gdb\Polygons",
                      r"C:\Git_Dan\npgeom\npGeo_1.gdb\x1",
                      "A0 = 'A' And A1 = 'a'")

View solution in original post

3 Replies
DanPatterson_Retired
MVP Esteemed Contributor

'And' just looks plain wrong

SQL reference for query expressions used in ArcGIS—ArcGIS Pro | ArcGIS Desktop 

"AREA" > 1500 AND "GARAGE" > 2

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

I guess 'And' is somehow correct , but I got failures without specifying a workspace first OR the full path to the source and destinations

arcpy.analysis.Select(r"C:\Git_Dan\npgeom\npgeom.gdb\Polygons",
                      r"C:\Git_Dan\npgeom\npGeo_1.gdb\x1",
                      "A0 = 'A' And A1 = 'a'")
RayHardjadinata1
New Contributor

Thank you! This works

0 Kudos