I was able to meet with one of my coworkers and he walked me through the steps successfully of arcpy.ArcSDESQLExecute(egdb). Now I am trying to export the SQL query results to a DBF or CSV file, any recommendations? Below is the script which will list results.
import arcpy
egdb = r'C:\Users\E149391\Documents\ArcGIS\Projects\ElectricMeterLatLong\esripubp.sde'
egdb_conn = arcpy.ArcSDESQLExecute(egdb)
sql = ''' 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' '''
egdb_return = egdb_conn.execute(sql)
for i in egdb_return:
print('{}: {}'.format(*i))
ArcSDESQLExecute
returns a Python list. Assuming the command is working and returning a Python list, this isn't a geospatial question any more. You should check Stack Overflow, I am certain the question of exporting a Python list to CSV has been answered multiple times.JOIN
syntax)csv
or ` pandas` python packages to output a csv.