Select to view content in your preferred language

Using SQL to "Select by Attributes" comparing fields...

6047
11
Jump to solution
01-28-2019 09:00 AM
AdrianWelsh
MVP Honored Contributor

I'm trying to write a simple SQL query that just isn't working. I have two fields in my file geodatabase layer (ArcGIS Pro 2.3) and I want to select the records that match my simple SQL query of:

written out to LEFT(Layer,3) = OWNERSHIP_NUMBER

But I get an error saying that "The SQL expression has invalid syntax".

I must be doing it wrong somewhere but I don't know where. These are both FIELDS and not RECORDS, so that likely makes a difference in how my syntax is supposed to be written.

Looking up this article: SQL reference for query expressions used in ArcGIS—ArcGIS Pro | ArcGIS Desktop 

it says "

String functions can be used to format strings. For instance, the LEFT function would return a certain number of characters starting on the left of the string. In this example, the query would return all states starting with the letter A:

LEFT(STATE_NAME,1) = 'A'

"

So, it makes me think my syntax is mostly right since both of my fields are strings. Any advice on making my SQL query syntax work?

0 Kudos
11 Replies
RandyBurton
MVP Alum

And the page referenced also says:

A Lot Has Changed Since SQL-92

And so it has.

AdrianWelsh
MVP Honored Contributor

Geeze, you're right! This is a great segment from that article:

The result of each of the following comparisons is therefore unknown:0

NULL = 1 
NULL <> 1 
NULL > 1 
NULL = NULL

Nothing equals null. Not even null equals null because each null could be different.

Haha, oh null. What a conundrum

0 Kudos