Selecting all values with by using SelectLayerByAttribute_management with input Parameter
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
add a comment |
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
add a comment |
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
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
arcpy select-by-attribute parameters null error-000358
edited Jan 16 at 11:11
PolyGeo♦
53.3k1779238
53.3k1779238
asked Jan 16 at 10:59
AndreasAndreas
183
183
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Use three quotes, AddFieldDelimiters and format:
sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
1
Thank you! Works perfect!
– Andreas
Jan 16 at 11:06
@Andreas Nice! Please accept my answer with the checkbox
– BERA
Jan 16 at 11:07
add a comment |
I think this should work:
sql = "{0} IS NULL".format(inputFieldname)
arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
I dont think it will with shape or fgdb input since they will need double quotes around the field name. UnlessinputFieldname = '"somefield"'
– BERA
Jan 16 at 11:20
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♦
Jan 16 at 11:27
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
Jan 16 at 11:32
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Use three quotes, AddFieldDelimiters and format:
sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
1
Thank you! Works perfect!
– Andreas
Jan 16 at 11:06
@Andreas Nice! Please accept my answer with the checkbox
– BERA
Jan 16 at 11:07
add a comment |
Use three quotes, AddFieldDelimiters and format:
sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
1
Thank you! Works perfect!
– Andreas
Jan 16 at 11:06
@Andreas Nice! Please accept my answer with the checkbox
– BERA
Jan 16 at 11:07
add a comment |
Use three quotes, AddFieldDelimiters and format:
sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
Use three quotes, AddFieldDelimiters and format:
sql = """{0} IS NULL""".format(arcpy.AddFieldDelimiters(datasource=inputFeature, field=inputFieldname))
ap.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
answered Jan 16 at 11:01
BERABERA
15.2k52042
15.2k52042
1
Thank you! Works perfect!
– Andreas
Jan 16 at 11:06
@Andreas Nice! Please accept my answer with the checkbox
– BERA
Jan 16 at 11:07
add a comment |
1
Thank you! Works perfect!
– Andreas
Jan 16 at 11:06
@Andreas Nice! Please accept my answer with the checkbox
– BERA
Jan 16 at 11:07
1
1
Thank you! Works perfect!
– Andreas
Jan 16 at 11:06
Thank you! Works perfect!
– Andreas
Jan 16 at 11:06
@Andreas Nice! Please accept my answer with the checkbox
– BERA
Jan 16 at 11:07
@Andreas Nice! Please accept my answer with the checkbox
– BERA
Jan 16 at 11:07
add a comment |
I think this should work:
sql = "{0} IS NULL".format(inputFieldname)
arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
I dont think it will with shape or fgdb input since they will need double quotes around the field name. UnlessinputFieldname = '"somefield"'
– BERA
Jan 16 at 11:20
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♦
Jan 16 at 11:27
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
Jan 16 at 11:32
add a comment |
I think this should work:
sql = "{0} IS NULL".format(inputFieldname)
arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
I dont think it will with shape or fgdb input since they will need double quotes around the field name. UnlessinputFieldname = '"somefield"'
– BERA
Jan 16 at 11:20
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♦
Jan 16 at 11:27
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
Jan 16 at 11:32
add a comment |
I think this should work:
sql = "{0} IS NULL".format(inputFieldname)
arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
I think this should work:
sql = "{0} IS NULL".format(inputFieldname)
arcpy.SelectLayerByAttribute_management(inputFeature,"NEW_SELECTION", sql)
answered Jan 16 at 11:14
PolyGeo♦PolyGeo
53.3k1779238
53.3k1779238
I dont think it will with shape or fgdb input since they will need double quotes around the field name. UnlessinputFieldname = '"somefield"'
– BERA
Jan 16 at 11:20
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♦
Jan 16 at 11:27
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
Jan 16 at 11:32
add a comment |
I dont think it will with shape or fgdb input since they will need double quotes around the field name. UnlessinputFieldname = '"somefield"'
– BERA
Jan 16 at 11:20
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♦
Jan 16 at 11:27
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
Jan 16 at 11:32
I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless
inputFieldname = '"somefield"'
– BERA
Jan 16 at 11:20
I dont think it will with shape or fgdb input since they will need double quotes around the field name. Unless
inputFieldname = '"somefield"'
– BERA
Jan 16 at 11:20
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♦
Jan 16 at 11:27
@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♦
Jan 16 at 11:27
1
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
Jan 16 at 11:32
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
Jan 16 at 11:32
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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