I am trying to run a SQL query in ArcGIS Pro ArcPy and I am getting errors. I have looked into the ArcSDESQLExecute sample query.
https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/arcsdesqlexecute.htm
The code below is what I have written:
import arcpy
egdb = r'C:\Users\E149391\Documents\ArcGIS\Projects\ElectricMeterLatLong\esripubp.sde'
egdb_conn = arcpy.ArcSDESQLExecute(egdb)
sql = r'C:\Users\E149391\Documents\ArcGIS\Projects\ElectricMeterLatLong\CustomerDataR.sql'
egdb_return = egdb_conn.execute(sql)
CustomerDataR.sql contains:
select b.servicepointglobalid as Svc_Glbl_ID, b.facilityid,
a.addressline1, a.addresscitystate, a.meternumber,
a.meterpointnumber, a.premise_num, a.SERVICE_PT_NUM, d.tmsnumber
from refgis.customerdatar a, elepub.electricmeter b,
elepub.transformer c, elepub.transformerunit d
where a.meterpointnumber = b.meterpointnumber and
a.premise_num = b.premisenumber and a.service_pt_num = b.servicepointnumber and
b.transformerglobalid = c.globalid and
c.facilityid = d.facilityid and a.statusmeter <> 'R' and
a.statusmeterrecord = 2 and
a.statename = 'MO';
Traceback (most recent call last): File "<string>", line 2, in <module> File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\arcobjects\arcobjects.py", line 44, in execute return convertArcObjectToPythonObject(self._arc_object.Execute(*gp_fixargs(args))) AttributeError: ArcSDESQLExecute: StreamExecute ArcSDE Extended error 900 ORA-00900: invalid SQL statement
JOIN
keyword was added to ANSI SQL in 1992. Using aFROM
table list 32 years later is decidedly NOT best practice.