Select to view content in your preferred language

Local variables in SQL statement of Python GIS

937
2
10-27-2011 01:27 PM
xiaojiabao
New Contributor
What is the appropriate format to use local variables in SQL statements under python GIS?

I came across error messages when I'm running the following:

bas=24
gp.Select(input, Output_Feature_Class, "\"BAS\"= bas")

However, it is ok if I run: gp.Select(input, Output_Feature_Class, "\"BAS\"= 24")

Appreciate any potential help.

Xi
Tags (2)
0 Kudos
2 Replies
LoganPugh
Frequent Contributor
You can't use local variable names directly -- you have to use string formatting or concatenation.

E.g.

bas=24
whereClause = "\"BAS\"= %d" % (bas)
gp.Select(input, Output_Feature_Class, whereClause)
0 Kudos
xiaojiabao
New Contributor
Thanks Logan,

That solved.
0 Kudos