SELECT * FROM (SELECT top 5 * FROM table1 UNION ALL SELECT top 10 * FROM table1) DERIVEDTBL一共显示15条,里面的条件按照自己的要求来写啊
晕~~ 你加个临表,所有数据插到临表,读临表就行啦~~或都用一个CDS或普通GRID也行
我提供3个方法: 1.直接用程序代码实现:procedure TRES_CQ_JBPG_F.cxButton2Click(Sender: TObject); begin inherited; if (Trim(cx_accountid.Text)='') then begin MessageDlg('請檢查:查詢的工號不能為空!',mtWarning,[mbOK],0); cx_accountid.SetFocus; Exit; end; if (Trim(cx_accountid.Text)<>'') then begin if Trim(StrWhere)='' then StrWhere:= 'where Account_Id='+quotedstr(Trim(cx_accountid.Text)) else StrWhere:=StrWhere+' or Account_Id='+quotedstr(Trim(cx_accountid.Text)); qry_hr.Close; qry_hr.SQL.Clear; qry_hr.SQL.Add('select * from Res_User_Temp '+StrWhere+' Order by OpDt desc'); qry_hr.Open; cx_accountid.SetFocus; cx_accountid.SelectAll; if qry_hr.RecordCount=0 then begin MessageDlg('請注意:沒有找到工號為"'''+ Trim(cx_accountid.Text)+'''"的人員資料!請與人資或資訊聯繫處理!!!',mtWarning,[mbOK],0); cx_accountid.SetFocus; Exit; end; end; end;2.用临时表,将数据插到表后再读出查询; 3.用SQL同表的UNION ALL关联方法。。
FROM (SELECT *
FROM table1
UNION ALL
SELECT *
FROM table2) DERIVEDTBL
我查询的是同一个表,只是判断条件不一样。有可能有无数次查询,我要求所查出来的结果全部同时透过Grid 显示出!
FROM (SELECT top 5 *
FROM table1
UNION ALL
SELECT top 10 *
FROM table1) DERIVEDTBL一共显示15条,里面的条件按照自己的要求来写啊
1.直接用程序代码实现:procedure TRES_CQ_JBPG_F.cxButton2Click(Sender: TObject);
begin
inherited;
if (Trim(cx_accountid.Text)='') then
begin
MessageDlg('請檢查:查詢的工號不能為空!',mtWarning,[mbOK],0);
cx_accountid.SetFocus;
Exit;
end;
if (Trim(cx_accountid.Text)<>'') then
begin
if Trim(StrWhere)='' then
StrWhere:= 'where Account_Id='+quotedstr(Trim(cx_accountid.Text))
else
StrWhere:=StrWhere+' or Account_Id='+quotedstr(Trim(cx_accountid.Text));
qry_hr.Close;
qry_hr.SQL.Clear;
qry_hr.SQL.Add('select * from Res_User_Temp '+StrWhere+' Order by OpDt desc');
qry_hr.Open;
cx_accountid.SetFocus;
cx_accountid.SelectAll;
if qry_hr.RecordCount=0 then
begin
MessageDlg('請注意:沒有找到工號為"'''+ Trim(cx_accountid.Text)+'''"的人員資料!請與人資或資訊聯繫處理!!!',mtWarning,[mbOK],0);
cx_accountid.SetFocus;
Exit;
end;
end;
end;2.用临时表,将数据插到表后再读出查询;
3.用SQL同表的UNION ALL关联方法。。