Selecting all values with by using SelectLayerByAttribute_management with input Parameter












2















I am trying to select all values with Null by using the SelectLayerByAttribute_management. But the Fieldname in the where-clause is alterable by using the input-parameter.



That is what i tried:



if inputValue == "Null":
ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", inputFieldname +"IS NULL")


Does somebody have an idea what I did wrong?
That's the error message i get:
ExecuteError: ERROR 000358: Invalid expression
Failed to execute (SelectLayerByAttribute).










share|improve this question





























    2















    I am trying to select all values with Null by using the SelectLayerByAttribute_management. But the Fieldname in the where-clause is alterable by using the input-parameter.



    That is what i tried:



    if inputValue == "Null":
    ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", inputFieldname +"IS NULL")


    Does somebody have an idea what I did wrong?
    That's the error message i get:
    ExecuteError: ERROR 000358: Invalid expression
    Failed to execute (SelectLayerByAttribute).










    share|improve this question



























      2












      2








      2








      I am trying to select all values with Null by using the SelectLayerByAttribute_management. But the Fieldname in the where-clause is alterable by using the input-parameter.



      That is what i tried:



      if inputValue == "Null":
      ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", inputFieldname +"IS NULL")


      Does somebody have an idea what I did wrong?
      That's the error message i get:
      ExecuteError: ERROR 000358: Invalid expression
      Failed to execute (SelectLayerByAttribute).










      share|improve this question
















      I am trying to select all values with Null by using the SelectLayerByAttribute_management. But the Fieldname in the where-clause is alterable by using the input-parameter.



      That is what i tried:



      if inputValue == "Null":
      ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", inputFieldname +"IS NULL")


      Does somebody have an idea what I did wrong?
      That's the error message i get:
      ExecuteError: ERROR 000358: Invalid expression
      Failed to execute (SelectLayerByAttribute).







      arcpy select-by-attribute parameters null error-000358






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      PolyGeo

      53.3k1779238




      53.3k1779238










      asked 1 hour ago









      AndreasAndreas

      183




      183






















          2 Answers
          2






          active

          oldest

          votes


















          2














          Use three quotes, AddFieldDelimiters and format:



          sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
          ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)





          share|improve this answer



















          • 1





            Thank you! Works perfect!

            – Andreas
            1 hour ago











          • @Andreas Nice! Please accept my answer with the checkbox

            – BERA
            1 hour ago



















          0














          I think this should work:



          sql = "{0} IS NULL".format(inputFieldname)
          arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)





          share|improve this answer
























          • I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless inputFieldname = '"somefield"'

            – BERA
            52 mins ago








          • 1





            @BERA My understanding is that ArcGIS has been very forgiving on field delimiters for the last 3-4 dot releases. I cannot remember the last time that I used them in an SQL expression like this with either a file geodatabase or a shapefile.

            – PolyGeo
            45 mins ago






          • 1





            I Think you are correct. I just tried it and it does work without field delimiters.

            – BERA
            40 mins ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "79"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f308816%2fselecting-all-values-with-null-by-using-selectlayerbyattribute-management-with%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Use three quotes, AddFieldDelimiters and format:



          sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
          ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)





          share|improve this answer



















          • 1





            Thank you! Works perfect!

            – Andreas
            1 hour ago











          • @Andreas Nice! Please accept my answer with the checkbox

            – BERA
            1 hour ago
















          2














          Use three quotes, AddFieldDelimiters and format:



          sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
          ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)





          share|improve this answer



















          • 1





            Thank you! Works perfect!

            – Andreas
            1 hour ago











          • @Andreas Nice! Please accept my answer with the checkbox

            – BERA
            1 hour ago














          2












          2








          2







          Use three quotes, AddFieldDelimiters and format:



          sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
          ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)





          share|improve this answer













          Use three quotes, AddFieldDelimiters and format:



          sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
          ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 1 hour ago









          BERABERA

          15.1k52042




          15.1k52042








          • 1





            Thank you! Works perfect!

            – Andreas
            1 hour ago











          • @Andreas Nice! Please accept my answer with the checkbox

            – BERA
            1 hour ago














          • 1





            Thank you! Works perfect!

            – Andreas
            1 hour ago











          • @Andreas Nice! Please accept my answer with the checkbox

            – BERA
            1 hour ago








          1




          1





          Thank you! Works perfect!

          – Andreas
          1 hour ago





          Thank you! Works perfect!

          – Andreas
          1 hour ago













          @Andreas Nice! Please accept my answer with the checkbox

          – BERA
          1 hour ago





          @Andreas Nice! Please accept my answer with the checkbox

          – BERA
          1 hour ago













          0














          I think this should work:



          sql = "{0} IS NULL".format(inputFieldname)
          arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)





          share|improve this answer
























          • I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless inputFieldname = '"somefield"'

            – BERA
            52 mins ago








          • 1





            @BERA My understanding is that ArcGIS has been very forgiving on field delimiters for the last 3-4 dot releases. I cannot remember the last time that I used them in an SQL expression like this with either a file geodatabase or a shapefile.

            – PolyGeo
            45 mins ago






          • 1





            I Think you are correct. I just tried it and it does work without field delimiters.

            – BERA
            40 mins ago
















          0














          I think this should work:



          sql = "{0} IS NULL".format(inputFieldname)
          arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)





          share|improve this answer
























          • I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless inputFieldname = '"somefield"'

            – BERA
            52 mins ago








          • 1





            @BERA My understanding is that ArcGIS has been very forgiving on field delimiters for the last 3-4 dot releases. I cannot remember the last time that I used them in an SQL expression like this with either a file geodatabase or a shapefile.

            – PolyGeo
            45 mins ago






          • 1





            I Think you are correct. I just tried it and it does work without field delimiters.

            – BERA
            40 mins ago














          0












          0








          0







          I think this should work:



          sql = "{0} IS NULL".format(inputFieldname)
          arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)





          share|improve this answer













          I think this should work:



          sql = "{0} IS NULL".format(inputFieldname)
          arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 58 mins ago









          PolyGeoPolyGeo

          53.3k1779238




          53.3k1779238













          • I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless inputFieldname = '"somefield"'

            – BERA
            52 mins ago








          • 1





            @BERA My understanding is that ArcGIS has been very forgiving on field delimiters for the last 3-4 dot releases. I cannot remember the last time that I used them in an SQL expression like this with either a file geodatabase or a shapefile.

            – PolyGeo
            45 mins ago






          • 1





            I Think you are correct. I just tried it and it does work without field delimiters.

            – BERA
            40 mins ago



















          • I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless inputFieldname = '"somefield"'

            – BERA
            52 mins ago








          • 1





            @BERA My understanding is that ArcGIS has been very forgiving on field delimiters for the last 3-4 dot releases. I cannot remember the last time that I used them in an SQL expression like this with either a file geodatabase or a shapefile.

            – PolyGeo
            45 mins ago






          • 1





            I Think you are correct. I just tried it and it does work without field delimiters.

            – BERA
            40 mins ago

















          I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless inputFieldname = '"somefield"'

          – BERA
          52 mins ago







          I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless inputFieldname = '"somefield"'

          – BERA
          52 mins ago






          1




          1





          @BERA My understanding is that ArcGIS has been very forgiving on field delimiters for the last 3-4 dot releases. I cannot remember the last time that I used them in an SQL expression like this with either a file geodatabase or a shapefile.

          – PolyGeo
          45 mins ago





          @BERA My understanding is that ArcGIS has been very forgiving on field delimiters for the last 3-4 dot releases. I cannot remember the last time that I used them in an SQL expression like this with either a file geodatabase or a shapefile.

          – PolyGeo
          45 mins ago




          1




          1





          I Think you are correct. I just tried it and it does work without field delimiters.

          – BERA
          40 mins ago





          I Think you are correct. I just tried it and it does work without field delimiters.

          – BERA
          40 mins ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f308816%2fselecting-all-values-with-null-by-using-selectlayerbyattribute-management-with%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Polycentropodidae

          Magento 2 Error message: Invalid state change requested

          Paulmy