By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,944 Members | 1,819 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,944 IT Pros & Developers. It's quick & easy.

passing input to sql query

P: 19
hi

i am using python code to execute SQL queries and here i have one table as follows
id country cost
11 INDIA 2342
12 USA 2444
13 PAK 2323
14 RUSSIA 2322

and here i am using multiple selection list for selecting the country and i am using the SQL query as follows

select sum(cost) from table where country in ('india','russia')

and how to pass the values to the query using the following python code

ds = runtime.getDataService()
out = ds.executeSql("select sum(cost) from table where country in (here i have to pass the input)")
print out


how to acheive this?
reply me ASAP
regards
yuvaraj
Mar 25 '08 #1
Share this Question
Share on Google+
3 Replies


jlm699
100+
P: 314
You should try to use code tags when posting as it makes your question much more readable. See the Posting Guidelines for more info.

You should use some string interpolation in this case.
Expand|Select|Wrap|Line Numbers
  1. out = ds.executeSql("select sum(cost) from table where country in (%s)" % "india, tturkey")
Mar 25 '08 #2

P: 19
hi
what u have given is good but here i am selecting the values from multiple selection list and store it in a variable consider it as input =(india,usa,pak) and here i have to pass the input to the query as follows
def examle(input):
ds = runtime.getDataService()
output = ds.executeSql("select sum(cost) from testing where country in (input)")
and the input may store more than one value
how to get this
reply me
regards
yuvaraj
Mar 27 '08 #3

jlm699
100+
P: 314
Please use code tags when posting as it makes your question more readable. Read the Posting Guidelines.

You should use string interpolation
Expand|Select|Wrap|Line Numbers
  1. out = ds.executeSql("select sum(cost) from table where country in (%s)" % input)
Mar 27 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.