4

I have a shp file (s.shp) with column "A" and column "B". I try copy from this file only that rows where string value from column "A" is part of string value from column "B" e.g.

A  
0.1  
0.2  
0.3  

B  
0.12  
0.21  
0.43

The output file should have two rows first and second.

I try make:

import arcpy  
source='c:\\MY\\s.shp'    
output='c:\\MY\\o.shp'  
arcpy.Select_analysis(source,output,"\"B\" like '%'||\"A\"||'%'")

but I have a error :(

ERROR 000358: Invalid expression "B" like '%'||"A"||'%'

I use ArcMap 10.1.

  • Which version of ArcGIS you are using? "I try copy from 'this file'" - Lookasz_BL (not clear which type of file you are using like text file, CSV file, or any other type). Please write the steps which you are doing to achieve your result so that others don't have to wonder about your approach. – Surya Aug 26 '14 at 7:36
  • Still not working :( arcpy.Select_analysis(source,output,"\"B\" like \'%\'||\"A\"||\'%\'") ERROR 000358: Invalid expression "B" like '%'||"A"||'%' To Hornbydd: These are not typical of the data. I need a universal solution. Whole text may be inside in string in column B. – Lookasz_BL Aug 26 '14 at 10:30
1

If your example is typical of what you are trying to select then if you convert your input dataset into a file geodatabase featureclass you could use the sql expression:

SUBSTRING( B, 1 , 3) = A

This will select rows where the first 3 characters of field B match the entire contents of field A.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.