php - Prepared statement - cross table update -


i attempting use prepared statement in combination cross table update. have prepared sample script representative of our larger database. first section want without prepared statement, hoping avoid copy/pasting every column of data.

set session group_concat_max_len = 1000000000; drop table if exists update_test; create table update_test( time_index decimal(12,4), varchar(20), b varchar(20), c varchar(20)); insert update_test(time_index) values(20150101.0000),(20150101.0015),(20150101.0030);  drop table if exists energy_values; create table energy_values( time_stamp decimal(12,4), site_id varchar(5), energy int); insert energy_values  values(20150101.0000,'a',100),(20150101.0000,'b',200),(20150101.0000,'c',300),       (20150101.0015,'a',400),(20150101.0015,'b',500),(20150101.0015,'c',600),       (20150101.0030,'a',700),(20150101.0030,'b',800),(20150101.0030,'c',900);  drop table if exists update_test_sites; create table update_test_sites( sites varchar(5)); insert update_test_sites values ('a'),('b'),('c');  update update_test, energy_values, update_test_sites set    update_test.a=energy_values.energy update_test.time_index = energy_values.time_stamp , energy_values.site_id ='a';  update update_test, energy_values, update_test_sites set    update_test.b=energy_values.energy update_test.time_index = energy_values.time_stamp , energy_values.site_id ='b';  update update_test, energy_values, update_test_sites set    update_test.c=energy_values.energy update_test.time_index = energy_values.time_stamp , energy_values.site_id ='c'; select * update_test; 

which why have attempted replacement update functions. however, syntax error report. can identify going wrong? appreciated!

select concat(  'update update_test, energy_values, update_test_sites set    update_test.',sites,'=energy_values.energy update_test.time_index = energy_values.time_stamp , energy_values.site_id = ',sites,'; select * update_test;')  update_test_sites sites = 'a' @sql;  prepare stmt @sql; execute stmt; 

i've never seen "select into" work way. in experience, used so:

select [field_list] [variable_list]  [some_table]  [etc...] 

i don't think can used store resultset appears attempting.

with tweaking , doing in stored procedure, use cursor iterate on results prepare , execute each generated statement individually.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -