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.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Database Connections\\Server Database sde.sde"</SPAN>
featureclasses <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> featureclasses<SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>CreateDatabaseView_management<SPAN class="punctuation token">(</SPAN>
fc<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Database Connections\\Server Database sde.sde"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"v_"</SPAN><SPAN class="operator token">+</SPAN>str<SPAN class="punctuation token">(</SPAN>featureclasses<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"select * from "</SPAN><SPAN class="operator token">+</SPAN>featureclasses<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>