EntryDM.ADOQR_quality_s_add_apply_check.Close ;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Clear ;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.add('select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp ');
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Append('from quality_s_add_apply_check where project_inspect_id=:str1 and cycle_number=:str2' );
EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str1').Value := gl_project_inspect_id;
EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str2').Value :=1;
EntryDM.ADOQR_quality_s_add_apply_check.ExecSQL ;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Clear;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Add('select * from #quality_s_add_apply_check_temp');//发现不存在刚才建的临时表
EntryDM.ADOQR_quality_s_add_apply_check.Open ;
我在execsql之前用了两个参数,到注释那一句就出错,说是没有刚才建的临时表
是不是execsql之前的SQL语句不能带参数?
如果不用参数,一切都ok,
如果能带,怎样带呢?
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Clear ;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.add('select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp ');
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Append('from quality_s_add_apply_check where project_inspect_id=:str1 and cycle_number=:str2' );
EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str1').Value := gl_project_inspect_id;
EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str2').Value :=1;
EntryDM.ADOQR_quality_s_add_apply_check.ExecSQL ;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Clear;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Add('select * from #quality_s_add_apply_check_temp');//发现不存在刚才建的临时表
EntryDM.ADOQR_quality_s_add_apply_check.Open ;
我在execsql之前用了两个参数,到注释那一句就出错,说是没有刚才建的临时表
是不是execsql之前的SQL语句不能带参数?
如果不用参数,一切都ok,
如果能带,怎样带呢?
strSQL:='select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp
from quality_s_add_apply_check where project_inspect_id=:str1 and cycle_number=:str2
select * from #quality_s_add_apply_check_temp'EntryDM.ADOQR_quality_s_add_apply_check.sql.clear;
EntryDM.ADOQR_quality_s_add_apply_check.sql.text:=strSQL; EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str1').Value := gl_project_inspect_id;
EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str2').Value :=1;EntryDM.ADOQR_quality_s_add_apply_check.ExecSQL ;
就可以了
AdoQuery.SQL.add('select * from t1 where id='''+str1+'''');
再有,问题不在于我后面怎样处从临时表中读数,而在于如果用到参数,临时表根本就不会建立,而且不报错,但我在执行后查看查询分析器时,里面根本不会有刚才想要创建的临时表。我会试试Debugxp的方法,他的也许行
完全可以用参数
肯定是别的原因
+
EntryDM.ADOQR_quality_s_add_apply_check.Close ;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Clear ;
EntryDM.ADOQR_quality_s_add_apply_check.SQL.add('select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp ');
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Append('from quality_s_add_apply_check where project_inspect_id=:str1 and cycle_number=:str2' );
EntryDM.ADOQR_quality_s_add_apply_check.SQL.Add('select * from #quality_s_add_apply_check_temp');//发现不存在刚才建的临时表
EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str1').Value := gl_project_inspect_id;
EntryDM.ADOQR_quality_s_add_apply_check.Parameters.ParamByName('str2').Value :=1;
EntryDM.ADOQR_quality_s_add_apply_check.Open ;好了,这样就可以得到临时表中的数据了。
EntryDM.ADOQR_quality_s_add_apply_check.SQL.add('select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp from quality_s_add_apply_check where project_inspect_id='+QuotedStr(gl_project_inspect_id)+' and cycle_number='
+QuotedStr(1));
可用TADODataSet组件,他有一个克隆的功能。
可以复制数据集从另一个TADODataSet组件,而且速度很快。
你在克隆的数据集进行操作不会影响到真正的数据库。
同时:
楼上说的ADS的这个COPY功能怎么设置?
create proc P_test(@s1 varchar(20),@s2 int)
as
begin
select identity(int,1,1) as id,examine_approve_date,real_added_s,add_s_apply_content into #quality_s_add_apply_check_temp
from quality_s_add_apply_check where project_inspect_id=@s1 and cycle_number=@S2
select * from #quality_s_add_apply_check_temp
return 0
end//delphi
//dbgrid的数据源联上ADOStoredProc1
procedure TForm1.Button1Click(Sender: TObject);
begin
with ADOStoredProc1 do
try
Close;
ProcedureName:='P_test;1';
Parameters.Refresh;
Parameters.ParamByName('@s1').Value:=gl_project_inspect_id;
Parameters.ParamByName('@s2').Value:=1;
Open;//返回数据集
if Parameters.ParamByName('@return_value').Value<> then Abort;
except
showmessage('error');
raise;
end;
end;
调用
begin
with adoquery1 do
begin
close;
sql.clear;
sql.Add(' select identity(int,1,1) as id ,字段 into #t1 from 表');
ExecSQL;
close;
sql.clear;
sql.Add('select * from #t1');
open;
end;
end;如果连续点俩次会报错#t已经存在
但是存储过程会自动释放临时表不用管