执行速度特别慢,麻烦帮忙看一下.(100分)

  • 主题发起人 主题发起人 yhd99
  • 开始时间 开始时间
Y

yhd99

Unregistered / Unconfirmed
GUEST, unregistred user!
程序如下:一分钟只能插入100条数据左右,有什么提高速度的办法吗?<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> &nbsp;yhd,hy_id,jffs_id,com_date,bank_id:string;<br> &nbsp;presenttime:tdatetime;<br> &nbsp;nian,yue,ri:word;<br> &nbsp;total_number,now_number,i:integer;<br>begin<br> &nbsp;for i:=0 to listbox1.Items.Count -1 &nbsp;do<br> &nbsp;begin<br> &nbsp; presenttime:=now;<br> &nbsp; decodedate(presenttime,nian,yue,ri);<br> &nbsp; if yue&lt;10 then<br> &nbsp; com_date:=inttostr(nian)+'-0'+inttostr(yue)<br> &nbsp; else<br> &nbsp; com_date:=inttostr(nian)+'-'+inttostr(yue);<br><br> &nbsp; query17.Close;<br> &nbsp; query17.sql.Clear;<br> &nbsp; query17.SQL.add('select * from ep_ammeter_data where to_char(exp_time,''yyyy-mm'')=:a and area_book=:b') ;<br> &nbsp; //query17.SQL.add('select * from ep_ammeter_data where to_char(exp_time,''yyyy-mm'')=:a and exp_sum &lt; 0') ;<br> &nbsp; query17.parambyname('a').value:=com_date;<br> &nbsp; query17.parambyname('b').value:=listbox1.Items;<br> &nbsp; query17.ExecSQL ;<br> &nbsp; query17.Open;<br> &nbsp; total_number:=query17.recordcount;<br> &nbsp; now_number:=0;<br> &nbsp; progressbar1.Min:=0;<br> &nbsp; progressbar1.Max:=total_number;<br> &nbsp; table18.close;<br> &nbsp; table18.TableName:='EP_AMMETER_DATA';<br> &nbsp; table18.open;<br> &nbsp; table18.active:=true;<br> &nbsp; while (not query17.eof) do<br> &nbsp; begin<br> &nbsp; now_number:=now_number + 1;<br> &nbsp; ProgressBar1.Position:=now_number;<br> &nbsp; {query37.close;<br> &nbsp; query37.sql.clear;<br> &nbsp; query37.SQL.add('select * from ep_ammeter_data where to_char(exp_time,''yyyy-mm'')=:a and kh_id=:b');<br> &nbsp; query37.parambyname('a').value:=com_date;<br> &nbsp; query37.parambyname('b').value:=query17.fieldbyname('kh_id').asstring;<br> &nbsp; query37.ExecSQL;<br> &nbsp; query37.open;<br> &nbsp; if query37.recordcount&gt;=1 then<br> &nbsp; begin<br> &nbsp; query38.close;<br> &nbsp; query38.sql.clear;<br> &nbsp; query38.SQL.add('delete from ep_ammeter_data where to_char(exp_time,''yyyy-mm'')=:a and kh_id=:b');<br> &nbsp; query38.parambyname('a').value:=com_date;<br> &nbsp; query38.parambyname('b').value:=query17.fieldbyname('kh_id').asstring;<br> &nbsp; query38.ExecSQL;<br> &nbsp; end; }<br> &nbsp; &nbsp; &nbsp;table18.append;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('unit_id').asstring:=query17.fieldbyname('unit_id').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('kh_id').asstring:=query17.fieldbyname('kh_id').asstring;<br> &nbsp; &nbsp; &nbsp;yhd:=query17.fieldbyname('kh_id').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('jld_id').asstring:=query17.fieldbyname('jld_id').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('abk_id').asstring:=query17.fieldbyname('abk_id').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('ammeter_no').asstring:=query17.fieldbyname('ammeter_no').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('price_id').asstring:=query17.fieldbyname('price_id').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('add_id').asstring:=query17.fieldbyname('add_id').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('area_book').asstring:=query17.fieldbyname('area_book').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('exp_time').asdatetime:=query17.fieldbyname('exp_time').asdatetime;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('compute_date').asdatetime:=query17.fieldbyname('compute_date').asdatetime;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('ep_status').asstring:=query17.fieldbyname('ep_status').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('mount_capa').asfloat:=query17.fieldbyname('mount_capa').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('smooth_capa').asfloat:=query17.fieldbyname('smooth_capa').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('valley_capa').asfloat:=query17.fieldbyname('valley_capa').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('nop_capa').asfloat:=query17.fieldbyname('nop_capa').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('elec_exp').asfloat:=query17.fieldbyname('elec_exp').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('capacity').asinteger:=query17.fieldbyname('capacity').asinteger;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('capa_e').asfloat:=query17.fieldbyname('capa_e').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('need_capa').asfloat:=query17.fieldbyname('need_capa').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('need_e').asfloat:=query17.fieldbyname('need_e').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('power_factor').asfloat:=query17.fieldbyname('power_factor').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('adj_ratio').asfloat:=query17.fieldbyname('adj_ratio').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('adj_plus').asfloat:=query17.fieldbyname('adj_plus').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('adj_neg').asfloat:=query17.fieldbyname('adj_neg').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('nwhd').asfloat:=query17.fieldbyname('nwhd').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('sxjj').asfloat:=query17.fieldbyname('sxjj').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('zhpt').asfloat:=query17.fieldbyname('zhpt').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('csfj').asfloat:=query17.fieldbyname('csfj').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('kqjj').asfloat:=query17.fieldbyname('kqjj').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('other1').asfloat:=query17.fieldbyname('other1').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('other2').asfloat:=query17.fieldbyname('other2').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('other3').asfloat:=query17.fieldbyname('other3').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('mount_exp').asfloat:=query17.fieldbyname('mount_exp').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('smooth_exp').asfloat:=query17.fieldbyname('smooth_exp').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('valley_exp').asfloat:=query17.fieldbyname('valley_exp').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('power_sum').asfloat:=query17.fieldbyname('power_sum').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('exp_sum').asfloat:=query17.fieldbyname('exp_sum').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('r_p_money').asfloat:=query17.fieldbyname('r_p_money').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('error_rp_money').asfloat:=query17.fieldbyname('error_rp_money').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('tine_capa').asfloat:=query17.fieldbyname('tine_capa').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('ridge_capa').asfloat:=query17.fieldbyname('ridge_capa').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('tine_exp').asfloat:=query17.fieldbyname('tine_exp').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('ridge_exp').asfloat:=query17.fieldbyname('ridge_exp').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('isadd').asstring:=query17.fieldbyname('isadd').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('serial_no').asstring:=query17.fieldbyname('serial_no').asstring;<br> &nbsp; &nbsp; &nbsp;{query20.close;<br> &nbsp; &nbsp; &nbsp;query20.sql.clear;<br> &nbsp; &nbsp; &nbsp;query20.sql.add('select * from ep_power_price_dic where price_id=:a');<br> &nbsp; &nbsp; &nbsp;query20.parambyname('a').value:=query17.fieldbyname('price_id').asstring;<br> &nbsp; &nbsp; &nbsp;query20.execsql;<br> &nbsp; &nbsp; &nbsp;query20.open;<br> &nbsp; &nbsp; &nbsp;table18.FieldByName('price_type').asstring:=query20.fieldbyname('price_type').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('n_basep').asfloat:=query20.fieldbyname('n_basep').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('c_basep').asfloat:=query20.fieldbyname('c_basep').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('vol_grade').asstring:=query20.fieldbyname('vol_grade').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('p_mount').asfloat:=query20.fieldbyname('p_mount').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('p_smooth').asfloat:=query20.fieldbyname('p_smooth').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('p_valley').asfloat:=query20.fieldbyname('p_valley').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('p_tine').asfloat:=query20.fieldbyname('p_tine').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('p_ridge').asfloat:=query20.fieldbyname('p_ridge').asfloat; <br> &nbsp; &nbsp; &nbsp;query20.close;<br> &nbsp; &nbsp; &nbsp;query20.sql.clear;<br> &nbsp; &nbsp; &nbsp;query20.sql.add('select * from ep_province_add_dic where add_id=:a');<br> &nbsp; &nbsp; &nbsp;query20.parambyname('a').value:=query17.fieldbyname('add_id').asstring;<br> &nbsp; &nbsp; &nbsp;query20.execsql;<br> &nbsp; &nbsp; &nbsp;query20.open;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('nwhd_price').asfloat:=query20.fieldbyname('nwhd').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('sxjj_price').asfloat:=query20.fieldbyname('sxjj').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('csfj_price').asfloat:=query20.fieldbyname('csfj').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('zhpt_price').asfloat:=query20.fieldbyname('zhpt').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('kqjj_price').asfloat:=query20.fieldbyname('kqjj').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('other1_price').asfloat:=query20.fieldbyname('other1').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('other2_price').asfloat:=query20.fieldbyname('other2').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('other3_price').asfloat:=query20.fieldbyname('other3').asfloat; }<br> &nbsp; &nbsp; &nbsp;query19.close;<br> &nbsp; &nbsp; &nbsp;query19.SQL.clear;<br> &nbsp; &nbsp; &nbsp;query19.sql.add('select * from po_khjbxx where kh_id=:a');<br> &nbsp; &nbsp; &nbsp;query19.parambyname('a').value:=yhd;<br> &nbsp; &nbsp; // showmessage(query19.SQL.DelimitedText);<br> &nbsp; &nbsp; &nbsp;query19.ExecSQL;<br> &nbsp; &nbsp; &nbsp;query19.open;<br> &nbsp; &nbsp; &nbsp;if query19.RecordCount&lt;1 then<br> &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;hy_id:=query19.fieldbyname('hy_id').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('hy_id').asstring:=query19.fieldbyname('hy_id').asstring;<br> &nbsp; &nbsp; &nbsp;if query19.fieldbyname('kh_name').asstring='' then table18.fieldbyname('kh_name').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('kh_name').asstring:=query19.fieldbyname('kh_name').asstring;<br> &nbsp; &nbsp; &nbsp;if query19.fieldbyname('yddz').asstring='' then table18.fieldbyname('yddz').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('yddz').asstring:=query19.fieldbyname('yddz').asstring;<br> &nbsp; &nbsp; &nbsp;if query19.fieldbyname('lxdz').asstring='' then table18.fieldbyname('lxdz').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('lxdz').asstring:=query19.fieldbyname('lxdz').asstring;<br> &nbsp; &nbsp; &nbsp;if query19.fieldbyname('ydlb_id').asstring='' then table18.fieldbyname('ydlb_id').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('ydlb_id').asstring:=query19.fieldbyname('ydlb_id').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('jffs').asstring:=query19.fieldbyname('jffs').asstring;<br> &nbsp; &nbsp; &nbsp;jffs_id:=query19.fieldbyname('jffs').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('gdfs').asstring:=query19.fieldbyname('gdfs').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('user_type').asstring:=query19.fieldbyname('user_type').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('yhlx_id').asstring:=query19.fieldbyname('yhlx_id').asstring;<br> &nbsp; &nbsp; &nbsp;if query19.fieldbyname('tel').asstring='' then table18.fieldbyname('link_tel').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('link_tel').asstring:=query19.fieldbyname('link_tel').AsString;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;query20.close;<br> &nbsp; &nbsp; &nbsp;query20.sql.clear;<br> &nbsp; &nbsp; &nbsp;query20.sql.add('select * from po_hyxx where hy_id=:a');<br> &nbsp; &nbsp; &nbsp;query20.parambyname('a').Value :=hy_id;<br> &nbsp; &nbsp; &nbsp;query20.execsql;<br> &nbsp; &nbsp; &nbsp;query20.open;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('hy_name').asstring:=query20.fieldbyname('hy_name').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('fjhy_id').asstring:=query20.fieldbyname('fjhy_id').asstring;<br> &nbsp; &nbsp; &nbsp;query20.close;<br> &nbsp; &nbsp; &nbsp;query20.sql.clear;<br> &nbsp; &nbsp; &nbsp;query20.sql.add('select * from ep_code_dic_deatail where sort_id=''12'' and code_id=:a');<br> &nbsp; &nbsp; &nbsp;query20.parambyname('a').value:=jffs_id;<br> &nbsp; &nbsp; &nbsp;query20.execsql;<br> &nbsp; &nbsp; &nbsp;query20.open;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('jffs_name').asstring:=query20.fieldbyname('code_name').asstring;<br> &nbsp; &nbsp; &nbsp;query20.close;<br> &nbsp; &nbsp; &nbsp;query20.sql.clear;<br> &nbsp; &nbsp; &nbsp;query20.sql.add('select * from ep_abn_para where ammeter_no=:a');<br> &nbsp; &nbsp; &nbsp;query20.parambyname('a').value:=query17.fieldbyname('ammeter_no').asstring;<br> &nbsp; &nbsp; &nbsp;query20.execsql;<br> &nbsp; &nbsp; &nbsp;query20.open;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('multiple').asfloat:=query20.fieldbyname('multiple').asfloat;<br> &nbsp; &nbsp; &nbsp;//table18.fieldbyname('amm_num').asinteger:=;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('line_time').asdatetime:=query20.fieldbyname('lin_time').asdatetime;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('in_time').asdatetime:=query20.fieldbyname('in_time').asdatetime;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('main_now').asfloat:=query20.fieldbyname('main_now').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('mount_now').asfloat:=query20.fieldbyname('mount_now').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('smooth_now').asfloat:=query20.fieldbyname('smooth_now').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('valley_now').asfloat:=query20.fieldbyname('valley_now').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('tine_now').asfloat:=query20.fieldbyname('tine_now').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('ridge_now').asfloat:=query20.fieldbyname('ridge_now').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('nop_now').asfloat:=query20.fieldbyname('nop_now').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('need_reading').asfloat:=query20.fieldbyname('need_reading').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('main_last').asfloat:=query20.fieldbyname('main_last').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('mount_last').asfloat:=query20.fieldbyname('mount_last').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('smooth_last').asfloat:=query20.fieldbyname('smooth_last').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('valley_last').asfloat:=query20.fieldbyname('valley_last').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('tine_last').asfloat:=query20.fieldbyname('tine_last').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('ridge_last').asfloat:=query20.fieldbyname('ridge_last').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('nop_last').asfloat:=query20.fieldbyname('nop_last').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('unusual_tag').asstring:=query20.fieldbyname('unusual_tag').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('input_tag').asstring:=query20.fieldbyname('input_tag').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('chg_sign').asstring:=query20.fieldbyname('chg_sign').asstring;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('p_chg_power').asfloat:=query20.fieldbyname('p_chg_power').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('v_chg_power').asfloat:=query20.fieldbyname('v_chg_power').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('s_chg_power').asfloat:=query20.fieldbyname('n_chg_power').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('t_chg_power').asfloat:=query20.fieldbyname('t_chg_power').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('r_chg_power').asfloat:=query20.fieldbyname('r_chg_power').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('power_trans').asfloat:=query20.fieldbyname('power_trans').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('no_power_trans').asfloat:=query20.fieldbyname('no_power_trans').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('lloss_capa').asfloat:=query20.fieldbyname('lloss_capa').asfloat;<br> &nbsp; &nbsp; &nbsp;{query20.close;<br> &nbsp; &nbsp; &nbsp;query20.sql.clear;<br> &nbsp; &nbsp; &nbsp;query20.sql.add('select * from po_ammeter_detail where abk_id=:a');<br> &nbsp; &nbsp; &nbsp;query20.parambyname('a').value:=query17.fieldbyname('abk_id').asstring;<br> &nbsp; &nbsp; &nbsp;query20.execsql;<br> &nbsp; &nbsp; &nbsp;query20.open;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('fix_ratio').asfloat:=query20.fieldbyname('fix_ratio').asfloat;<br> &nbsp; &nbsp; &nbsp;table18.fieldbyname('fix_capa').asfloat:=query20.fieldbyname('fix_capa').asfloat; }<br> &nbsp; &nbsp; &nbsp;query21.Close;<br> &nbsp; &nbsp; &nbsp;query21.sql.clear;<br> &nbsp; &nbsp; &nbsp;query21.sql.add('select * from ep_area_book_info where area_book=:a');<br> &nbsp; &nbsp; &nbsp;query21.parambyname('a').value:=query17.fieldbyname('area_book').asstring;<br> &nbsp; &nbsp; &nbsp;query21.execsql;<br> &nbsp; &nbsp; &nbsp;query21.open;<br> &nbsp; &nbsp; &nbsp;if query21.fieldbyname('copy_id').asstring='' then table18.fieldbyname('charge_id').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('charge_id').asstring:=query21.fieldbyname('copy_id').asstring;<br> &nbsp; &nbsp; &nbsp;if query21.fieldbyname('copy_name').asstring='' then table18.fieldbyname('charge_man').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('charge_man').asstring:=query21.fieldbyname('copy_name').asstring;<br> &nbsp; &nbsp; &nbsp;if query21.fieldbyname('yyz_id').asstring='' then table18.fieldbyname('yyz_id').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('yyz_id').asstring:=query21.fieldbyname('yyz_id').asstring;<br> &nbsp; &nbsp; &nbsp;if query21.fieldbyname('yyz_name').asstring='' then table18.fieldbyname('yyz_name').asstring:='-'<br> &nbsp; &nbsp; &nbsp;else table18.fieldbyname('yyz_name').asstring:=query21.fieldbyname('yyz_name').asstring;<br> &nbsp; &nbsp; &nbsp;query20.close;<br> &nbsp; &nbsp; &nbsp;query20.sql.clear;<br> &nbsp; &nbsp; &nbsp;query20.sql.add('select * from ep_user_para where kydw_id=:a');<br> &nbsp; &nbsp; &nbsp;query20.parambyname('a').value:=query17.fieldbyname('kh_id').asstring;<br> &nbsp; &nbsp; &nbsp;query20.execsql;<br> &nbsp; &nbsp; &nbsp;query20.open;<br> &nbsp; &nbsp; &nbsp;if query20.RecordCount&lt;1 then<br> &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if query20.fieldbyname('balance_name').asstring='' then table18.fieldbyname('balance_name').asstring:='-'<br> &nbsp; &nbsp; &nbsp; &nbsp;else table18.fieldbyname('balance_name').asstring:=query20.fieldbyname('balance_name').asstring;<br> &nbsp; &nbsp; &nbsp; &nbsp;if query20.fieldbyname('cons_id').asstring='' then table18.fieldbyname('cons_id').asstring:='-'<br> &nbsp; &nbsp; &nbsp; &nbsp;else table18.fieldbyname('cons_id').asstring:=query20.fieldbyname('cons_id').asstring;<br> &nbsp; &nbsp; &nbsp; &nbsp;if query20.fieldbyname('bank_id').asstring='' then table18.FieldByName('bank_id').asstring:='-'<br> &nbsp; &nbsp; &nbsp; &nbsp;else table18.fieldbyname('bank_id').asstring:=query20.fieldbyname('bank_id').asstring;<br> &nbsp; &nbsp; &nbsp; &nbsp;bank_id:=query20.fieldbyname('bank_id').asstring;<br> &nbsp; &nbsp; &nbsp; &nbsp;if query20.fieldbyname('account_id').asstring='' then table18.fieldbyname('account_id').asstring:='-'<br> &nbsp; &nbsp; &nbsp; &nbsp;else table18.fieldbyname('account_id').asstring:=query20.fieldbyname('account_id').asstring;<br> &nbsp; &nbsp; &nbsp; &nbsp;query20.close;<br> &nbsp; &nbsp; &nbsp; &nbsp;query20.sql.clear;<br> &nbsp; &nbsp; &nbsp; &nbsp;query20.sql.add('select * from po_bank where bank_id=:a');<br> &nbsp; &nbsp; &nbsp; &nbsp;query20.parambyname('a').value:=bank_id;<br> &nbsp; &nbsp; &nbsp; &nbsp;query20.ExecSQL;<br> &nbsp; &nbsp; &nbsp; &nbsp;query20.Open;<br> &nbsp; &nbsp; &nbsp; &nbsp;if query20.fieldbyname('bank_name').asstring='' then table18.fieldbyname('bank_name').asstring:='-'<br> &nbsp; &nbsp; &nbsp; &nbsp;else table18.fieldbyname('bank_name').asstring:=query20.fieldbyname('bank_name').asstring;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;query17.next;<br> &nbsp; &nbsp; &nbsp;table18.post;<br><br> &nbsp; end;<br> &nbsp; end;<br>end;
 
看起来累。<br>你很多地方都可以修改。<br>// &nbsp; &nbsp;query17.sql.add('select * from ep_ammeter_data where to_char(exp_time,''yyyy-mm'')=:a and area_book=:b');<br> &nbsp; //为了取得记录总数代价太大....<br> &nbsp; &nbsp;query17.sql.add('select count(*) as 总数 from ep_ammeter_data where to_char(exp_time,''yyyy-mm'')=:a and area_book=:b');
 
不好意思,query17还要循环,并不只是去总数
 
这样做真的好累
 
to zywcd<br>您认为如何修改为好呢?
 
看起来眼花、头大...你应当对代码优化。
 
也太长了点,建议能用存储过程的用存储过程,或是把数据放在结构体中也许会快多,至少没你这么乱,编程也要professional
 
先把需求分析清楚吧,这样建数据库的时候根据需求,进行处理,会提高优化的速度,还有就是使用存储过程,将数据处理这一块丢给数据库服务器,这两个办法都是优化的办法。
 
直接写Insert语句,应该会提高不少<br> fieldbyname('').as..:=fieldbyname('').as...;<br>这种方法是最低效的,时间都浪费在查找字段和数据转换上面了。
 
看得真累呀!!!
 
问题是这样,要从多个表中取值,然后插入另外的一个表中.比如说a、b、c三个表,如果用多表关联的话,假如b表没有符合的记录,那么检索出来的结果为空。但是只要a表有数据,无论b表是否有对应的 数据,都得向d表中插入数据。<br>所以这个关联sql语句不知道如何去写,所以才写的这么复杂。另外这三个表都是别的系统建立的表,不能修改结构.
 
用存储过程。每次只要传递新值即可。很快的
 
如果数据库用SQL SERVER 那么这些操作可以考虑用存储过程再配合一些视图
 
query19.ExecSQL;<br>query19.open;<br>这两行连在一起用是什么意思呀
 

Similar threads

后退
顶部