unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
DataSource1: TDataSource;
DataSource2: TDataSource;
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
Button2: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure pdm(Memo: TMemo;edit: TEdit);
function pds(Memo: TMemo):string;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,js:integer;
str:string;
begin
js:=0;
ADOQuery2.Active:=false;
ADOQuery2.SQL.Text:='select * from a where a=''3'' or b=''3'' ';
ADOQuery2.Active:=true;
while js<>ADOQuery2.RecordCount do
begin
//00
js:=ADOQuery2.RecordCount;
Memo1.Clear;
if ADOQuery2.RecordCount>=1 then
begin
//0
ADOQuery2.First;
while not ADOQuery2.Eof do
begin
edit1.Text:=trim(ADOQuery2.fieldbyname('a').AsString);
pdm(Memo1,edit1);
edit1.Text:=trim(ADOQuery2.fieldbyname('b').AsString);
pdm(Memo1,edit1);
ADOQuery2.Next;
end;
end;
//0
str:=pds(Memo1);
str:='select * from a where a in ('+str+') or b in ('+str+')' ;
edit2.Text:=str;
ADOQuery2.Active:=false;
ADOQuery2.SQL.Text:=str;
ADOQuery2.Active:=true;
end;
//00
end;
procedure TForm1.pdm(Memo: TMemo;
edit: TEdit);
var
i,j,t:integer;
begin
j:=memo.Lines.Count;
t:=1;
for i:=0 to j-1 do
begin
if trim(edit.Text)=trim(memo.Lines.Strings)
then
t:=0;
end;
if t=1 then
memo.Lines.Add(trim(edit.Text))
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit2.Text:=pds(Memo1);
end;
function TForm1.pds(Memo: TMemo):string;
var
i,j:integer;
s,str,yin:string;
begin
s:='';
yin:='''';
j:=memo1.Lines.Count;
for i:=0 to j-1 do
begin
if i=memo1.Lines.Count-1 then
s:=s+yin+trim(memo1.Lines.Strings)+yin
else
s:=s+yin+trim(memo1.Lines.Strings)+yin+','
end;
str:=s;
pds:=str;
end;
end.