<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Inline Variable Substitution for Dynamic Database Connection String in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246149#M26660</link>
    <description>&lt;P&gt;Thank you R_!&lt;/P&gt;&lt;P&gt;I'll try it and get back with you.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Jan 2023 19:25:42 GMT</pubDate>
    <dc:creator>ABishop</dc:creator>
    <dc:date>2023-01-06T19:25:42Z</dc:date>
    <item>
      <title>Inline Variable Substitution for Dynamic Database Connection String</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246137#M26658</link>
      <description>&lt;P&gt;Hopefully I am posting this in the right place and this makes sense to somebody who can assist me...&lt;/P&gt;&lt;P&gt;I wrote a series of python scripts which extracts data tables from views in our CAMA database.&amp;nbsp; Our CAMA database rolls over each year with a new year and consequentially the year has to be updated in the database connection string and view name.&amp;nbsp; This wouldn't be so bad if there weren't 30+ lines in each script and approx. 10 scripts that have year-dependent values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have looked into inline subs using variables and attempted a couple of different methods.&amp;nbsp; I have pasted one test script of a view extraction example below.&amp;nbsp; Could somebody review it and assist me with where I am going wrong?&amp;nbsp; &amp;nbsp;(Note: I am using ArcGIS Pro 3.0.3, ArcGIS Server 10.8, and Enterprise geodatabase in MS SQL Server version 14.0.1000.169)&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# Process: import arcpy modules
import arcpy, os, sys
from arcpy import env
from datetime import datetime
import ctypes
ctypes.windll.kernel32.SetConsoleTitleW('02_ExtractViews')
env.workspace = r"K:\GIS_UPDATE\DATA\EXTRACTVIEWS"
env.overwriteOutput = True

# Process: start timer
startTime = time.perf_counter()

# Process: set local variables
fieldmap = ""
RollYear = "2023"
AddressExtractView = r"K:\GIS_TOOLS\DB\CAMA(%RollYear%).sde\(%RollYear%).dbo.AddressExtractView(%RollYear%)"
gdb = r"K:\GIS_UPDATE\DATA\EXTRACTVIEWS\EXTRACTVIEWS.gdb"

# Process: copying AddressExtract View to Address1 table in EXTRACTVIEWS.gdb
arcpy.conversion.TableToTable(AddressExtractView, gdb, "Address1", '', fieldmap, '')

# Process: end timer
endTime = time.perf_counter()
elapsedTime = round((endTime - startTime) / 60, 2)
print("Script finished in {0} minutes".format(elapsedTime))

# Process: date and time stamp
date = datetime.now().strftime("%Y_%m_%d-%I:%M:%S_%p")
print("Date and time stamp: "+f"{date}")

# Process: provide input to stop script - uncomment input below if you need to see the script final output in the command window
input('Press ENTER to exit') &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance,&lt;/P&gt;&lt;P&gt;Amanda&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 18:57:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246137#M26658</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2023-01-06T18:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: Inline Variable Substitution for Dynamic Database Connection String</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246147#M26659</link>
      <description>&lt;P&gt;For variable substitution in the AddressExtractView string?&amp;nbsp; You can use f string substitution like such:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;AddressExtractView = fr"K:\GIS_TOOLS\DB\CAMA{RollYear}.sde\{RollYear}.dbo.AddressExtractView{RollYear}"&lt;/LI-CODE&gt;&lt;P&gt;If I understand the question correctly.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 19:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246147#M26659</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2023-01-06T19:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Inline Variable Substitution for Dynamic Database Connection String</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246149#M26660</link>
      <description>&lt;P&gt;Thank you R_!&lt;/P&gt;&lt;P&gt;I'll try it and get back with you.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 19:25:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246149#M26660</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2023-01-06T19:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Inline Variable Substitution for Dynamic Database Connection String</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246150#M26661</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;!&amp;nbsp; This worked beautifully.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 19:28:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/inline-variable-substitution-for-dynamic-database/m-p/1246150#M26661</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2023-01-06T19:28:12Z</dc:date>
    </item>
  </channel>
</rss>

