Select to view content in your preferred language

Using STR function in Arcpy Statement

2572
10
Jump to solution
01-31-2019 03:03 PM
Brian_McLeer
Occasional Contributor III

I have created an SDE database in which I have copied feature classes from my production database from State Plane into WGS 84 for web mapping applications. The final step is to create views, and I am trying to automate the process as I have hundreds of feature classes.

Below, I am trying to make a list of all the feature classes and use the name of the feature class. The middle parameter starts with a prefix of v_ then grabs the feature class name (ie: v_watermeters). The third variable is the SQL statement used to create the view definition, where it grabs all the fields (SELECT * FROM ) then I want to use the feature class name (ie: SELECT * FROM watermeters). 

I am having trouble with the third variable and concatenating the string values to make valid code.

We are currently on ArcGIS 10.3.1 and SQL Server 2012.

import arcpy
import os
arcpy.env.workspace = "Database Connections\\Server Database sde.sde"
featureclasses = arcpy.ListFeatureClasses()

for fc in featureclasses:
 arcpy.arcpy.CreateDatabaseView_management(
 fc, os.path.join("Database Connections\\Server Database sde.sde","v_"+str(featureclasses), "select * from "+featureclasses)
Brian
0 Kudos
10 Replies
Brian_McLeer
Occasional Contributor III

Thank you, that one worked after removing the double 'arcpy'. 

Brian
0 Kudos