能不能给我一些动态赋值SQL语句的例子小弟这两天正在为此事而烦恼请各位大虾慷慨解囊。(40分)

  • 主题发起人 主题发起人 篮球飞人
  • 开始时间 开始时间

篮球飞人

Unregistered / Unconfirmed
GUEST, unregistred user!
能不能给我一些动态赋值SQL语句的例子小弟这两天正在为此事而烦恼请各位大虾
慷慨解囊。
 
随手写的,你是一下。
begin
with ADOQuery1 do
begin
SQL.Clear;
SQL.Add('select * from Relic where No=:C1');
Parameters[0].value:=Edit1..Text;
ExecSQL;
open;
end;
 
不知道算不算?
strSQL:='select a.zhi as zhi,sum(a.bbyml) as bbyml,avg(a.dwfrl) as dwfrl,';
strSQL:=strSQL+'sum(a.bbyml*a.dwfrl/29.308) as zbml,';
strSQL:=strSQL+'avg(b.lh1_lzkrw) as lh1_lzkrw,avg(b.lh2_lzkrw) as lh2_lzkrw,';
strSQL:=strSQL+'avg(b.lh3_lzkrw) as lh3_lzkrw,';
strSQL:=strSQL+'sum((c.sz-c.jz)*c.pl)/sum(a.bbyml) as fdymhl,';
strSQL:=strSQL+'sum((d.sz-d.jz)*d.pl)/sum(a.bbyml) as gdymhl,';
strSQL:=strSQL+'sum((c.sz-c.jz)*c.pl)/sum(a.bbyml*a.dwfrl/29.308) as fdbmhl,';
strSQL:=strSQL+'sum((d.sz-d.jz)*d.pl)/sum(a.bbyml*a.dwfrl/29.308) as gdbmhl ';
strSQL:=strSQL+' from view_yx_rlmhy as a,view_mzfx_lzjybgb as b,';
strSQL:=strSQL+' dl_data as c,dl_data as d ';
strSQL:=strSQL+'where a.rq=b.rq and b.rq=c.rq and c.rq=d.rq ';
strSQL:=strSQL+' and a.zhi=b.zhi and b.zhi=c.bz and c.bz=d.bz ';
strSQL:=strSQL+' and c.fl='''+'发电量'+''''+' and d.fl='''+'供电量'+'''';
strSQL:=strSQL+' and convert(varchar(10),a.rq,10)>=''';
strSQL:=strSQL+FormatDateTime('yyyy-MM-dd',dtpBeginDate.Date)+'''';
strSQL:=strSQL+' and convert(varchar(10),a.rq,10)<=''';
strSQL:=strSQL+FormatDateTime('yyyy-MM-dd',dtpEndDate.Date)+'''';
strSQL:=strSQL+' group by a.zhi ';
strSQL:=strSQL+' union all ';
strSQL:=strSQL+'select '''+'合计'+''' as zhi,sum(a.bbyml) as bbyml,avg(a.dwfrl) as dwfrl,';
strSQL:=strSQL+'sum(a.bbyml*a.dwfrl/29.308) as zbml,';
strSQL:=strSQL+'avg(b.lh1_lzkrw) as lh1_lzkrw,avg(b.lh2_lzkrw) as lh2_lzkrw,';
strSQL:=strSQL+'avg(b.lh3_lzkrw) as lh3_lzkrw,';
strSQL:=strSQL+'sum((c.sz-c.jz)*c.pl)/sum(a.bbyml) as fdymhl,';
strSQL:=strSQL+'sum((d.sz-d.jz)*d.pl)/sum(a.bbyml) as gdymhl,';
strSQL:=strSQL+'sum((c.sz-c.jz)*c.pl)/sum(a.bbyml*a.dwfrl/29.308) as fdbmhl,';
strSQL:=strSQL+'sum((d.sz-d.jz)*d.pl)/sum(a.bbyml*a.dwfrl/29.308) as gdbmhl ';
strSQL:=strSQL+' from view_yx_rlmhy as a,view_mzfx_lzjybgb as b,';
strSQL:=strSQL+' dl_data as c,dl_data as d ';
strSQL:=strSQL+'where a.rq=b.rq and b.rq=c.rq and c.rq=d.rq ';
strSQL:=strSQL+' and a.zhi=b.zhi and b.zhi=c.bz and c.bz=d.bz ';
strSQL:=strSQL+' and c.fl='''+'发电量'+''''+' and d.fl='''+'供电量'+'''';
strSQL:=strSQL+' and convert(varchar(10),a.rq,10)>=''';
strSQL:=strSQL+FormatDateTime('yyyy-MM-dd',dtpBeginDate.Date)+'''';
strSQL:=strSQL+' and convert(varchar(10),a.rq,10)<=''';
strSQL:=strSQL+FormatDateTime('yyyy-MM-dd',dtpEndDate.Date)+'''';
if(frmDM.cdsTotalMData.Active=true) then
frmDM.cdsTotalMData.Active:=false;
frmDM.cdsTotalMData.CommandText:=strSQL;
frmDM.cdsTotalMData.Active:=true;
 
楼上的已经给你很多例子了,我就不说了。
up
 
hug的例子中,应该把execsql改为open
 
ADOQuery1.close;
ADOQuery1.SQL.Text:='select * from TableName where :str like
''%''+trim(name)+''%''';
ADOQuery1.Parameters.ParamByName('str').Value:='sky';
ADOQuery1.open;
 
begin
with ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select * from Relic where No=:C1');
Parameters[0].value:=Edit1..Text;
open;
end;
 
对不起各位大虾们,小弟就搞不懂是Parameters是什么东东,所以才不知怎么动态赋值
SQL语句的,再劳各位大驾,给予我解释。
 
对不起各位大虾们,小弟就搞不懂是Parameters是什么东东,所以才不知怎么动态赋值
SQL语句的,再劳各位大驾,给予我解释。
 
后退
顶部