I am using ArcGIS 10.1 and am a newbie in Python. Currently we are executing stored procedure (from sql server) through ArcPy in ArcMap. I want to create feature class from executing following python script.

I researched on Google but unable to find proper way/parameter in ArcPy. Currently going through following parameters GetParameter & GetMessage

Any help/steps will be great!

My ArcPy Script :

import sys
import arcpy
from arcpy import env

    # Make data path relative
    arcpy.env.workspace = sys.path[0]

# Two ways to create the object, which also creates the
# connection to ArcSDE.
# Using the first method, pass a set of strings containing
# the connection properties:
#   <serverName>, <portNumber>, <version>, <userName>, <password>
#   arcpy.ArcSDESQLExecute("locolhost","5151","#","Admin","password")
# Using the second method pass the path to a valid ArcSDE connection file
sde_conn = arcpy.ArcSDESQLExecute(r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\test.sde")

# Get the SQL statements, separated by ; from a text string.
#sql_statement = 'select Name from all_points'
sql_statement = 'Exec [dbo].[sp_test]'
sql_statement_list = sql_statement.split(";")


# For each SQL statement passed in, execute it.
for sql in sql_statement_list:
    print("Execute SQL Statement: {0}".format(sql))
        # Pass the SQL statement to the database.
        sde_return = sde_conn.execute(sql)
    except Exception as err:
        sde_return = False

    # If the return value is a list (a list of lists), display
    # each list as a row from the table being queried.
    if isinstance(sde_return, list):
        print("Number of rows returned by query: {0} rows".format(
        for row in sde_return:
        # If the return value was not a list, the statement was
        # most likely a DDL statment. Check its status.
        if sde_return == True:
            print("SQL statement: {0} ran successfully.".format(sql))
            print("SQL statement: {0} FAILED.".format(sql))

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.