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 1 hour ago
PolyGeo♦
53.3k1779238
53.3k1779238
asked 1 hour ago
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
1 hour ago
@Andreas Nice! Please accept my answer with the checkbox
– BERA
1 hour ago
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
1 hour 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♦
58 mins ago
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
53 mins ago
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
1 hour ago
@Andreas Nice! Please accept my answer with the checkbox
– BERA
1 hour ago
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
1 hour ago
@Andreas Nice! Please accept my answer with the checkbox
– BERA
1 hour ago
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 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
add a comment |
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
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
1 hour 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♦
58 mins ago
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
53 mins ago
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
1 hour 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♦
58 mins ago
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
53 mins ago
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 1 hour ago
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
1 hour 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♦
58 mins ago
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
53 mins ago
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
1 hour 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♦
58 mins ago
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
53 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
1 hour 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
1 hour 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♦
58 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♦
58 mins ago
1
1
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
53 mins ago
I Think you are correct. I just tried it and it does work without field delimiters.
– BERA
53 mins ago
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