Select to view content in your preferred language

Using a where clause in a search cursor

708
3
Jump to solution
12-09-2021 12:37 PM
LoganBohn
New Contributor

Hello all, I am pretty new to programming and arcpy. I am attaching a code where I am trying to take an input country from a user and use it in the where clause to return a list of the population ranks present for that country. As it is now, it returns an error that a column was specified that does not exist. The issue is in my query, but I cannot figure out how to format it to only return results from a certain country. Don't worry about the 2nd half of the code, as I am just trying to figure out this search cursor. 

 

Thanks!!

 

 

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

You want the following SQL query:

CNTRY_NAME = 'Country'

To get that as a string in PYthon:

query = "CNTRY_NAME = '{}'".format(country)

Have a great day!
Johannes

View solution in original post

3 Replies
DanPatterson
MVP Esteemed Contributor
country = 'x'

f'"CNTRY_NAME" = {country}'
'"CNTRY_NAME" = x'

perhaps


... sort of retired...
0 Kudos
JohannesLindner
MVP Frequent Contributor

You want the following SQL query:

CNTRY_NAME = 'Country'

To get that as a string in PYthon:

query = "CNTRY_NAME = '{}'".format(country)

Have a great day!
Johannes
LoganBohn
New Contributor

Thank you so much! I knew it was probably an easy answer but I had been trying to wrap my head around it for hours!

0 Kudos