How to add bind variables to complex SQL Update statement?
490060Feb 8 2007 — edited Feb 9 2007I have the following sql query that I am currently executing within a service method (see below.) I would like to convert this query to be contained within a view object associated with an entity object, and use bind variables for the where clause parameters. I can set the bind variable values in a service method when the view object is executed.
I'm not sure though how to include a query like this within a view object since a view object associated with an entity object expects a sql select statement versus an update statement containting sub-selects. I'm looking for any ideas how I can include this query within a view object, or, I don't mind keeping the query defined in the service method as a prepared statement but I need help how to set it up using bind variables?
thanks
SQL Update Statement contained in Service Method:
sqlstmt =
"update CUSTOMER set AVERAGE =
(select round((avg(value1) + avg(value2) + avg(value3) )/3.0) " +
"from RATINGTABLE where key ='" + key + "'), " +
"totratings = (select count(*) from RATINGTABLE where key ='" + key + "') " +
"where key ='" + key + "'";