SQL中记录改写条件???(100分)

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

yhongzhi

Unregistered / Unconfirmed
GUEST, unregistred user!
多表SQL查询改写条件,
请举例???
 
在程序中动态指定呀
你要达到什么效果了
如果是用query那可以在程序中这样写
query1.close;
query1.sql.clear;
query1.sql.add('select * from 你的表 where 你的条件');
query1.prepare;
query1.open;
 
按上面方法即可,还可以:
query1.close;
query1.sql.clear;
query1.Text = 'new sql';
query1.prepare;
query1.open;

 
没说清楚,或许我可以帮你。starbzj@371.net
 
qydate.Close;
qydate.SQL.Clear;
qydate.SQL.Add(' select c.productname,a.productno,a.grade,a.gperm2,a.packperset, '+
' a.pages,a.sizespec,a.unitweight,count(stackno) countt,sum(packperset) pack, '+
' (sum(packperset)*a.unitweight/1000.0) grosss,b.classno '+
' from productdata a,stacknumbers b,products c '+
' where a.productno=b.productno ');
qydate.SQL.Add(' and a.productcode=c.productcode ');
qydate.SQL.Add(' and b.status<>"C" and b.status<>"c"');
qydate.SQL.Add(' and convert(datetime,convert(char(10),B.dateinserted,111))='''+ s_datestr +'''');
qydate.SQL.Add(' group by c.productname,a.productno,a.grade,a.gperm2,a.packperset, '+
' a.pages,a.sizespec,a.unitweight,b.classno ');
qydate.Prepare;
qydate.Open;
可以吗?
 
用TQuery做查询,用TEdit输入查询条件:
with UQuerydo
begin
Close;
SQL.Clear;
SQL.Add('select field1,field2 from UTable where fiele3=:UParam');
ParamByName('UParam').asString:=Edit1.Text;
Prepare;
Open;
end;

更改条件时在Edit1中输入,然后:
Close;
ParamByName('UParam').asString:=Edit1.Text;
Prepare;
Open;

 
yhongzhi说的是改写吧 ???
Update ?
 
你的意思就是动态组织SQL语句,是吧?
给你一个比较简单点的例子,看看。
这是三层结构中,通过ClientDataSet改写服务端的SQL语句中的程序。
procedure TRe_Ghdwwl_frm.BitBtn1Click(Sender: TObject);
var
n,m:Integer;
sql,sql1,s_com,s_item:wideString;
dat1,dat2:string;
begin

if sbStrarDate.Down then
dat1:=DateTimeToStr(dtpStrarDate.dateTime)
else
dat1:='1980-01-01';
if sbLastDate.Down then
dat2:=DateTimeToStr(dtpLastDate.dateTime)
else
dat2:='2100-01-01';
m:=lvComList.Items.Count;
if spComList.Down and (m>0) then
begin
s_com:=' and comdcode in ( ';
for n:=1 to mdo
begin
if m=n then
s_com:=s_com+''''+lvComList.Items[n-1].Caption+''''+')'
else
s_com:=s_com+''''+lvComList.Items[n-1].Caption+''',';
end;
end;

m:=lvItemList.Items.Count;
if spItemList.Down and (m>0) then
begin
s_item:=' and itemdcode in ( ';
for n:=1 to mdo
begin
if m=n then
s_item:=s_item+''''+lvItemList.Items[n-1].Caption+''''+')'
else
s_item:=s_item+''''+lvItemList.Items[n-1].Caption+''',';
end;
end;

sql:=' Select comdcode,comname,Sum(amtpaid) as a,0 as b,0 as c,0 as d '
+' from t_salelist Where optype=''购入'' '+s_com+s_item+' and whflag>=''2'' and saleflag>=''2'' and configdate<=#'+dat1+'# '
+' GROUP BY comdcode,comname '
+' union '
+' Select comdcode,comname,0 as a,Sum(tamt) as b,0 as c,0 as d '
+' from t_salelist Where optype=''购入'' '+s_com+s_item+' and whflag>=''2'' and saleflag>=''2'' and configdate>=#'+dat1+'# and configdate<=#'+dat2+'# '
+' GROUP BY comdcode,comname '
+' union '
+' Select comdcode,comname,0 as a,0 as b,Sum(tamt-amtpaid) as c,0 as d '
+' from t_salelist Where optype=''购入'' '+s_com+s_item+' and whflag>=''2'' and saleflag>=''2'' and configdate>=#'+dat1+'# and configdate<=#'+dat2+'# '
+' GROUP BY comdcode,comname '
+' union '
+' Select comdcode,comname,0 as a,0 as b,0 as c,Sum(amtpaid) as d '
+' from t_salelist Where optype=''购入'' '+s_com+s_item+' and whflag>=''2'' and saleflag>=''2'' and configdate<=#'+dat2+'# '
+' GROUP BY comdcode,comname ';

sql1:=s_item+' and configdate>=#'+dat1+'# and configdate<=#'+dat2+'# ';
if cdsGhwl_a.Active then
cdsGhwl_a.Close;
if cdsGhwl.Active then
cdsGhwl.Close;
cdsGhwl.DataRequest(sql);
cdsGhwl_b.DataRequest(sql1);
cdsGhwl.Open;
pnlFind.Visible:=False;
end;
 
收获不少
 
接受答案了.
 
后退
顶部