<?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: Python script, SQL syntax within CalculateField question, missing quotes? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191486#M14716</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The + signs are used because ScriptSub is a variable and the Tool requires that there be quotes around that parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I know, your ScriptSub value is already a text string, but that's what the tool requires for whatever reason.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you simply put 'ScriptSub', it would literally put the word ScriptSub in every record, therefore the quotes around the variable.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Dec 2010 16:54:00 GMT</pubDate>
    <dc:creator>RDHarles</dc:creator>
    <dc:date>2010-12-03T16:54:00Z</dc:date>
    <item>
      <title>Python script, SQL syntax within CalculateField question, missing quotes?</title>
      <link>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191483#M14713</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Here's my code, the problem is calling the string variable &lt;/SPAN&gt;&lt;STRONG&gt;ScriptSub &lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;I know this isn't complex but it's going to save me a ton of time if I can just get this right.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I know that I'm probably just missing a double or single quote somewhere.&amp;nbsp; I really need this to work.&amp;nbsp; Thanks in advance.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import sys
import string
import os
import arcgisscripting

gp = arcgisscripting.create(9.3)

# Set a default workspace
gp.workspace = "C:\working\Y2010\Franks\Plant"
# Set a toolbox
gp.toolbox = "management"

ScriptNm = sys.argv[0]
ScriptSub = os.path.basename(ScriptNm)

try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; #Add fields
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.addfield ("\\FT_testing.gdb\FT_2010_P000\FT10_P180_Plant_test", "Depth_ft", "float", "5", "2")
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.addfield ("\\FT_testing.gdb\FT_2010_P000\FT10_P180_Plant_test", "Script", "text", "15")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurs when running Addfield, print out the error message.
&amp;nbsp;&amp;nbsp;&amp;nbsp; print gp.GetMessages(2)

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ############################
&amp;nbsp;&amp;nbsp;&amp;nbsp; # CALCULATIONS
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management("\\FT_testing.gdb\FT_2010_P000\FT10_P180_Plant_test", "Depth_ft", "[ftbathy] * 3.2808 ", "VB")

&amp;nbsp;&amp;nbsp;&amp;nbsp; #This line is the problem&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RIGHT HERE ???
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management("\\FT_testing.gdb\FT_ 2010_P000\FT10_P180_Plant_test", "Script", 'ScriptSub', "VB", "")&amp;nbsp;&amp;nbsp;&amp;nbsp; 

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurs when running Addfield, print out the error message.
&amp;nbsp;&amp;nbsp;&amp;nbsp; print gp.GetMessages(2)
try:

&amp;nbsp;&amp;nbsp;&amp;nbsp; print ScriptNm
&amp;nbsp;&amp;nbsp;&amp;nbsp; print ScriptSub

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurs when running Addfield, print out the error message.
&amp;nbsp;&amp;nbsp;&amp;nbsp; print gp.GetMessages(2)

&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Dec 2010 02:16:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191483#M14713</guid>
      <dc:creator>BryceStath</dc:creator>
      <dc:date>2010-12-03T02:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, SQL syntax within CalculateField question, missing quotes?</title>
      <link>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191484#M14714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I see a few problems:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1.) Change your backslashes to forward slashes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2.) To get the script name (a variable) populated in a field, use single AND double quotes like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;'"'+ScriptSub+'"'&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Dec 2010 12:45:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191484#M14714</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2010-12-03T12:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, SQL syntax within CalculateField question, missing quotes?</title>
      <link>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191485#M14715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But what are the + signs for?&amp;nbsp; I have not seen this anywhere in the documentation I've been looking at.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there any documentation where I can see this?&amp;nbsp; That would help me understand this better.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I'm running 9.3.&amp;nbsp; Maybe it's time to upgrade??&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Dec 2010 16:17:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191485#M14715</guid>
      <dc:creator>BryceStath</dc:creator>
      <dc:date>2010-12-03T16:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, SQL syntax within CalculateField question, missing quotes?</title>
      <link>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191486#M14716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The + signs are used because ScriptSub is a variable and the Tool requires that there be quotes around that parameter.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I know, your ScriptSub value is already a text string, but that's what the tool requires for whatever reason.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you simply put 'ScriptSub', it would literally put the word ScriptSub in every record, therefore the quotes around the variable.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Dec 2010 16:54:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191486#M14716</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2010-12-03T16:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, SQL syntax within CalculateField question, missing quotes?</title>
      <link>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191487#M14717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;rdharles,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I really appreciate your help.&amp;nbsp; I understand what you are saying about the quotes and the syntax.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've found a work around that is actually going to be much more efficient.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below is what's working for me, I'm going to build upon it.&amp;nbsp; It's a lot sleeker looking and more functional than what I was using, so it's even better than I originally had. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried the exact syntax in my older scripts and I generate the same errors.&amp;nbsp; So I'm a bit at a loss for why that is.&amp;nbsp; It probably has something to do with the client I'm using, or something behind the scenes.&amp;nbsp; For now, this will work.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I got the base part from ArcScripts, the link is&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://arcscripts.esri.com/details.asp?dbid=14534" rel="nofollow noopener noreferrer" target="_blank"&gt;http://arcscripts.esri.com/details.asp?dbid=14534&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#-----------------------------------------------------------------------------------------------------------
# File Name Insert
# Script written by Rocky Rudolph - April, 2006 - Channel Islands National Park, California
# Purpose: for creating a field called "FILENAME" and attaching the filename of the shapefile to each entry 
#&amp;nbsp;&amp;nbsp; in the attribute table. Use with as many shapefiles within a specified directory.
#&amp;nbsp;&amp;nbsp; Useful when picking apart shapefile entries and combining into a separate file to
#&amp;nbsp;&amp;nbsp; maintain a breadcrumb trail of the original shapefile name.&amp;nbsp; 
#
# Run file within a directory containing all the shapfiles needing modification
# Make sure FILENAME field doesn't already exist in any of the shapefiles
#
#-----------------------------------------------------------------------------------------------------------

#import relevant modules, create geoprocessing dispatch object
import win32com.client, sys, string, os

gp = win32com.client.Dispatch("esriGeoprocessing.gpDispatch.1")

# Remember to change this to wherever your shapefiles are stored
gp.workspace = "C:\\working\\Y2010\\Franks\\Plant\\FT_testing.gdb\\testing"

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcs = gp.ListFeatureClasses("*", "all")
&amp;nbsp;&amp;nbsp;&amp;nbsp; fcs.reset()
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = fcs.Next()

&amp;nbsp;&amp;nbsp;&amp;nbsp; Script = sys.argv[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; ScriptSub = os.path.basename(Script)

&amp;nbsp;&amp;nbsp;&amp;nbsp; print Script
&amp;nbsp;&amp;nbsp;&amp;nbsp; print ScriptSub
&amp;nbsp;&amp;nbsp;&amp;nbsp; 

&amp;nbsp;&amp;nbsp;&amp;nbsp; while fc:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Create the new field
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.AddField_management (fc, "FILENAME", "text", "", "", "50")

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Apply the filename to all entries&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.CalculateField_management (fc, "FILENAME", '"' + ScriptSub + '"')
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fc = fcs.Next()

except:
 print gp.GetMessages ()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:37:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191487#M14717</guid>
      <dc:creator>BryceStath</dc:creator>
      <dc:date>2021-12-11T09:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python script, SQL syntax within CalculateField question, missing quotes?</title>
      <link>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191488#M14718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can also do something like&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management(featureclass, "SPACESEARCH", '"%s-%s%s" % (!FACILITY!,!FLOOR!,!ROOM!)', "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; gp.CalculateField_management (fc, "FILENAME", '"%s" % ScriptSub')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;should also work&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Dec 2010 12:47:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-sql-syntax-within-calculatefield/m-p/191488#M14718</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2010-12-22T12:47:32Z</dc:date>
    </item>
  </channel>
</rss>

