全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1347
推到 Plurk!
推到 Facebook!

请高手帮助如何写这个SQL 语句啊???????

尚未結案
plmm3D
一般會員


發表:1
回覆:0
積分:0
註冊:2005-02-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-12-26 22:08:45 IP:61.149.xxx.xxx 訂閱
如贴图所示,在DBGridEh中调用查询库表,有三个字段:B,S,G以及判断字段Sf,其中B,S,G三个字段与主数据库表中的Bb,Ss,Gg对应.现在的目标是:
1:判断Sf是否被勾选:False or True;
2:如果多行的Sf是被勾选(True)的,则使用查询库表中所有被选定行的三个字段:B,S,G去主数据库表中找出Bb=B,Ss=S,Gg=G的所有记录;

(图例说明所使用的查询库表的相似结构,实际字段如上述)

以前的代码:
查询库表的三个字段:B,S,G的St勾选(True)正确,但是只能匹对一行,而且结果0,错误:
procedure TForm1.RzBitBtn31Click(Sender: TObject);
var
iIndex : integer;
begin
iIndex := 0;
sSQLCondition := '';
sSQLCondition1 := '';
sSQLCondition2 := '';
sSQLCondition3 := '';

with DataModule33.Zuhmsh53AllTable do
begin
if not Active then
Open;
DisableControls;
First;
while not Eof do
begin
if FieldByName('St').AsBoolean = true then
begin
if iIndex = 0 then
sSQLCondition := sSQLCondition;
sSQLCondition1 := sSQLCondition1;
sSQLCondition2 := sSQLCondition2;
sSQLCondition3 := sSQLCondition3;
iIndex := iIndex 1;
sSQLCondition := sSQLCondition FieldByName('53Bb').AsString;
sSQLCondition := sSQLCondition FieldByName('53Ss').AsString;
sSQLCondition := sSQLCondition FieldByName('53Gg').AsString;

end;
DataModule33.Zuhmsh53AllTable.Next;
end;
//if iIndex <> 0 then
//sSQLCondition := sSQLCondition ')';
First;
EnableControls;
end;
ShowMessage(sSQLCondition);
end;

procedure TForm1.RzBitBtn3Click(Sender: TObject);
var
S_sql:string;
begin
with DataModule33.Base33Ball53Query do
begin
DataModule33.Base33Ball53Query.Close;
DataModule33.Base33Ball53Query.SQL.Clear;
if sSQLCondition = '' then
S_sql:='Select * from Mother33Ball53'
else
S_sql:='select * from Mother33Ball53';
S_Sql:=s_sql ' where Mother33Ball53.ABb53=''';
S_Sql:=s_sql ''' and Mother33Ball53.ASs53=''';
S_Sql:=s_sql ''' and Mother33Ball53.AGg53=''';
S_Sql:=s_sql sSQLCondition '''';
DataModule33.Base33Ball53Query.SQL.Add(S_sql);
DataModule33.Base33Ball53Query.Prepare;
DataModule33.Base33Ball53Query.Open;
Next;
end;
StatusBar1.Panels[1].Text:='' '当前为' DataModule33.Zuhmsh53AllTable.fieldbyname('53Bb').asstring DataModule33.Zuhmsh53AllTable.fieldbyname('53Ss').asstring DataModule33.Zuhmsh53AllTable.fieldbyname('53Gg').asstring ' ' '共有' inttostr(DataModule33.Base33Ball53Query.RecordCount) '条记录';
end;
編輯記錄
taishyang 重新編輯於 2010-12-26 19:09:29, 註解 無‧
plmm3D 重新編輯於 2010-12-27 09:01:02, 註解 無‧
plmm3D 重新編輯於 2011-01-11 21:31:22, 註解 無‧
plmm3D 重新編輯於 2011-01-11 21:32:00, 註解 無‧
系統時間:2024-04-27 2:45:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!