import arcpy,sys try: arcpy.env.workspace = r'C:\staging\database connections\dev' sdes = arcpy.ListWorkspaces() for sde in sdes: arcpy.env.workspace = sde first = raw_input("Do you want to update aliases in "+str(sde)+"...\n(Yes/No)\n") if first.upper() == 'YES': fcs = arcpy.ListFeatureClasses() for fc in fcs: sde_conn = arcpy.ArcSDESQLExecute(sde) sql_stmt = "select Definition.value('(/DEFeatureClassInfo/Name/node())[1]', 'nvarchar(max)') AS Name, Definition.value('(/DEFeatureClassInfo/AliasName/node())[1]', 'nvarchar(max)') AS Alias from agdc_sde.sde.gdb_items where Name = '"+str(fc)+"'" sde_return = sde_conn.execute(sql_stmt) if sde_return == True: print "SQL statement: {0} ran successfully.".format(sql) else: print "SQL statement: {0} FAILED.".format(sql) print "+++++++++++++++++++++++++++++++++++++++++++++\n" except Exception as err: print unicode(err) sde_return = False
Solved! Go to Solution.
" select Definition.value('(/DEFeatureClassInfo/Name/node())[1]', 'nvarchar(max)') AS Name, Definition.value('(/DEFeatureClassInfo/AliasName/node())[1]', 'nvarchar(max)') AS Alias from agdc_sde.sde.gdb_items where Name = '"+str(fc)+"'"
Encountered this same issue and found this post.
Using ArcGIS Desktop 10.5.1.7333 (Python 2.7.13)
SQL Server 13.0.5026.0
I was able to go all the way up to nvarchar(4000). The context is I am returning some results in a python toolbox / geoprocessing service to be passed back to a WAB site so the result is being returned using the "FOR JSON AUTO" options in the SQL query to be easily parsed in JavaScript using a custom widget. There was a specific desire to stay within the ArcGIS stack rather than create a separate web service to return these results.