I am trying to teach myself to access sql tables from an ArcPy script as part of a larger QC process. I am fairly certain that I have the sql statement correct (it works in SQL Server, albeit formatted a little differently), but I have no clue how to return my declared sql variable back as a python variable so that I may run other stuff on it.

I am trying to check a sql table in an ArcSDE Database where the value of a single column is smaller than 1000 and larger than 10. If there are values outside this range, I need to run other processes.

This is what I've got so far:

SDE = r'Database Connections\NC_RISK - 106.sde'
SQLLink = arcpy.ArcSDESQLExecute(SDE)

sql = '''DECLARE @MyBadIndicator int; SET @MyBadIndicator = 0; SET @MyBadIndicator = SELECT 1 WHERE EXISTS (SELECT L_HAZARDPROBABILITY.F_EVENT

How do a get the value of MyBadIndicator so that ArcPy can use it?

  • 1
    ODBC doesn't really consider variables to be valid objects (in fact, they didn't exist when ODBC was created). You need to make a query which returns a row to interact with ArcGIS. – Vince Jan 12 '16 at 15:08

Your Answer

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

Browse other questions tagged or ask your own question.