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 16 hours ago









      PolyGeo

      53.3k1779238




      53.3k1779238










      asked 16 hours ago









      AndreasAndreas

      183




      183






















          2 Answers
          2






          active

          oldest

          votes


















          3














          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
            16 hours ago











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

            – BERA
            16 hours ago



















          1














          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
            16 hours ago








          • 3





            @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
            16 hours ago






          • 1





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

            – BERA
            16 hours 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









          3














          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
            16 hours ago











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

            – BERA
            16 hours ago
















          3














          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
            16 hours ago











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

            – BERA
            16 hours ago














          3












          3








          3







          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 16 hours ago









          BERABERA

          15.1k52042




          15.1k52042








          • 1





            Thank you! Works perfect!

            – Andreas
            16 hours ago











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

            – BERA
            16 hours ago














          • 1





            Thank you! Works perfect!

            – Andreas
            16 hours ago











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

            – BERA
            16 hours ago








          1




          1





          Thank you! Works perfect!

          – Andreas
          16 hours ago





          Thank you! Works perfect!

          – Andreas
          16 hours ago













          @Andreas Nice! Please accept my answer with the checkbox

          – BERA
          16 hours ago





          @Andreas Nice! Please accept my answer with the checkbox

          – BERA
          16 hours ago













          1














          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
            16 hours ago








          • 3





            @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
            16 hours ago






          • 1





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

            – BERA
            16 hours ago
















          1














          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
            16 hours ago








          • 3





            @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
            16 hours ago






          • 1





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

            – BERA
            16 hours ago














          1












          1








          1







          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 16 hours 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
            16 hours ago








          • 3





            @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
            16 hours ago






          • 1





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

            – BERA
            16 hours 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
            16 hours ago








          • 3





            @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
            16 hours ago






          • 1





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

            – BERA
            16 hours 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
          16 hours 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
          16 hours ago






          3




          3





          @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
          16 hours 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
          16 hours ago




          1




          1





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

          – BERA
          16 hours ago





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

          – BERA
          16 hours 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

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар