topo_geo

create sql query with arcsde connection

Discussion created by topo_geo on Jul 19, 2013
Latest reply on Jul 22, 2013 by topo_geo
hi,
i'm trying to execute this python script to establish aan sql query and the result is

"Execute SQL Statement: select [objectid) from [P10TN_SIG.DBO.BCBATIMS] where [shape.area] > 200"

<type 'exceptions.Exception'>   'ascii' codec can't encode character u'\ue51c' in position 52: ordinal not in range(128)

please help

>>> try:
...    env.workspace = (r"c:\connectionfiles\con21.sde")
...    sdeConn = arcpy.ArcSDESQLExecute(r"c:\connectionfiles\con21.sde")
...    SQLStatement = ("select [objectid) from [P10TN_SIG.DBO.BCBATIMS] where [shape.area] > 200")
...    SQLStatementList = SQLStatement.split(";")
...    print "\n"
... # For each SQL statement passed in, execute it.
...    for sql in SQLStatementList:
...       print "Execute SQL Statement: " + sql
...       try :
... #Pass the SQL statement to the database.
...          sdeReturn = sdeConn.execute(sql)
...       except Exception, ErrorDesc:
...          print ErrorDesc
...          sdeReturn = 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(sdeReturn, list):
...          print "Number of rows returned by query: " + len(sdeReturn), "rows"
...          for row in sdeReturn:
...             print row
...          print "\n"
...       else:
... #If the return value was not a list, the statement was most likely a DDL statment.
... #Check its status.
...          if sdeReturn == True:
...             print "SQL statement: " + sql + " ran sucessfully."
...             print "\n"
...          else :
...             print "SQL statement: " + sql + " FAILED."
...             print "\n"
... except Exception, ErrorDesc:
...    print Exception, ErrorDesc
... except:
...    print "Problem executing SQL."
... 
Execute SQL Statement: select [objectid) from [P10TN_SIG.DBO.BCBATIMS] where [shape.area] > 200

<type 'exceptions.Exception'>   'ascii' codec can't encode character u'\ue51c' in position 52: ordinal not in range(128)

>>> 

Outcomes