请高手帮助如何写这个SQL 语句啊??????? |
尚未結案
|
plmm3D
一般會員 ![]() ![]() 發表:1 回覆:0 積分:0 註冊:2005-02-19 發送簡訊給我 |
如贴图所示,在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; |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |