personalt wrote: > I read that page last night.. That sounded like what I wanted to do but I > had no idea how to get my simple query to be a parameterized query. That > is really what I was looking for help on. > > select kwhcost1 from applications; > > SELECT monitordata_hourly.deviceaddress, > Round(Sum(monitordata_hourly.ch1kwh),3) AS SumOfch1kwh, > Round(Sum(monitordata_hourly.ch1kwh),3)*.19 AS SumOfch1kwh_cost > FROM monitordata_hourly > Where monitordata_hourly.deviceaddress=142265 and > (datetime(monitordata_hourly.date))>=datetime('now', 'localtime', '-30 > days') > Group by monitordata_hourly.deviceaddress
So you run the first query (select kwhcost1 from applications;) and retrieve the KWH value into a variable in your program. Then you prepare (using sqlite3_prepare[_v2]) your second query with a parameter: SELECT monitordata_hourly.deviceaddress, Round(Sum(monitordata_hourly.ch1kwh),3) AS SumOfch1kwh, Round(Sum(monitordata_hourly.ch1kwh),3)* ? AS SumOfch1kwh_cost FROM monitordata_hourly Where monitordata_hourly.deviceaddress=142265 and (datetime(monitordata_hourly.date))>=datetime('now', 'localtime', '-30 days') Group by monitordata_hourly.deviceaddress Note the question mark in place of hardcoded .19. You may also want to parameterize other hardcoded constants while you are at it. Anyway, next you use a suitable sqlite3_bind_* flavor to bind the parameter (sqlite3_bind_double in your case), several calls to sqlite3_step to iterate over the resultset, and finally sqlite3_reset (if you want to reuse the query) or sqlite3_finalize (if you are done with it). Igor Tandetnik _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users