query.sql.add select(' count(1) as aNum from (select ' + combobox.text + ' from DB_indetail where ' + combobox.text + '=''' + edit1.test + ''' and flag=1) as p');
query.sql.add('selectcount(1) as aNum from (select ' + combobox.text + ' from DB_indetail where ' + combobox.text + '=''' + edit1.test + ''' and flag=1) as p');
with ADOQuery2 do begin close; sql.Clear; sql.Add('select count(1) as aNum from'); sql.Add('(select YZFL from DB_InDetail where YZFL =:a and flag=1) as p'); parameters.ParamByName('a').Value:=Trim(ComboBox1.Text); open; end; StoreNum:=ADOQuery2.FieldByName('aNum').AsInteger;这样写,统计出来的数据都是0,不知道问什么?
with adoquery2 do begin close; sql.clear; sql.add(' select YZFL from DB_InDetail where YZFL =:a and flag=1 '); parameters.ParamByName('a').Value:=Trim(ComboBox1.Text); open; if isEmpty then StoreNum:=0 else StoreNum:=recordcount; end;
基礎的東東,自己參考一下..... procedure TRes_Hr_JSD_F.SearchJS; begin if (Trim(cxTextEdit3.Text)='') and (Trim(cxDateEdit1.Text)='') then begin MessageDlg('操作提示:請檢查,查詢的條件不能為空!',mtWarning,[mbOK],0); Exit; end; if (Trim(cxTextEdit3.Text)<>'') and (Trim(cxDateEdit1.Text)='') then begin qry_search.Close; qry_search.SQL.Clear; qry_search.SQL.Add( ' select * from RES_HR_RSJS where GH='''+ Trim(cxTextEdit3.Text)+''' and PARTID in (select bmbh from RES_DEPARTMENT where fzr='+ QuotedStr(_UserName)+') ' ); qry_search.Open; if qry_search.RecordCount=0 then begin MessageDlg('查詢提示:沒有找到符合查詢條件(或當前用戶權限)的記錄!',mtWarning,[mbOK],0); Exit; end; end; if (Trim(cxTextEdit3.Text)='') and (Trim(cxDateEdit1.Text)<>'') then begin qry_search.Close; qry_search.SQL.Clear; qry_search.SQL.Add( ' select * from RES_HR_RSJS where SXRQ='''+ FormatDateTime('yyyy/mm/dd',cxDateEdit1.Date)+''' and PARTID in (select bmbh from RES_DEPARTMENT where fzr='+ QuotedStr(_UserName)+') ' ); qry_search.Open; if qry_search.RecordCount=0 then begin MessageDlg('查詢提示:沒有找到符合查詢條件(或當前用戶權限)的記錄!',mtWarning,[mbOK],0); Exit; end; end; if (Trim(cxTextEdit3.Text)<>'') and (Trim(cxDateEdit1.Text)<>'') then begin qry_search.Close; qry_search.SQL.Clear; qry_search.SQL.Add( ' select * from RES_HR_RSJS where GH='''+ Trim(cxTextEdit3.Text)+''' and SXRQ='''+ FormatDateTime('yyyy/mm/dd',cxDateEdit1.Date)+''' and PARTID in (select bmbh from RES_DEPARTMENT where fzr='+ QuotedStr(_UserName)+') ' ); qry_search.Open; if qry_search.RecordCount=0 then begin MessageDlg('查詢提示:沒有找到符合查詢條件(或當前用戶權限)的記錄!',mtWarning,[mbOK],0); Exit; end; end; end;
拼一下就行了, 楼上都把答案给了关于为什么得到0,似乎是没有这条记录吧, Count = 0
const str:string = ' select YZFL from DB_InDetail where YZFL =%s and flag=1 '; var s:string; begin s := Format(str,[Quostrd(Trim(ComboBox1.Text))]); with adoquery2 do begin close; sql.clear; sql.add(s); open; end; end;
with ADOQuery2 do
begin
close;
sql.Clear;
sql.Add('select count(1) as aNum from');
sql.Add('(select YZFL from DB_InDetail where YZFL =:a and flag=1) as p');
parameters.ParamByName('a').Value:=Trim(ComboBox1.Text);
open;
end;
StoreNum:=ADOQuery2.FieldByName('aNum').AsInteger;这样写,统计出来的数据都是0,不知道问什么?
begin
close;
sql.clear;
sql.add(' select YZFL from DB_InDetail where YZFL =:a and flag=1 ');
parameters.ParamByName('a').Value:=Trim(ComboBox1.Text);
open;
if isEmpty then
StoreNum:=0
else
StoreNum:=recordcount;
end;
前者不能使用参数,只能拼凑sql
procedure TRes_Hr_JSD_F.SearchJS;
begin
if (Trim(cxTextEdit3.Text)='') and (Trim(cxDateEdit1.Text)='') then
begin
MessageDlg('操作提示:請檢查,查詢的條件不能為空!',mtWarning,[mbOK],0);
Exit;
end;
if (Trim(cxTextEdit3.Text)<>'') and (Trim(cxDateEdit1.Text)='') then
begin
qry_search.Close;
qry_search.SQL.Clear;
qry_search.SQL.Add( ' select * from RES_HR_RSJS where GH='''+ Trim(cxTextEdit3.Text)+''' and PARTID in (select bmbh from RES_DEPARTMENT where fzr='+ QuotedStr(_UserName)+') ' );
qry_search.Open;
if qry_search.RecordCount=0 then
begin
MessageDlg('查詢提示:沒有找到符合查詢條件(或當前用戶權限)的記錄!',mtWarning,[mbOK],0);
Exit;
end;
end;
if (Trim(cxTextEdit3.Text)='') and (Trim(cxDateEdit1.Text)<>'') then
begin
qry_search.Close;
qry_search.SQL.Clear;
qry_search.SQL.Add( ' select * from RES_HR_RSJS where SXRQ='''+ FormatDateTime('yyyy/mm/dd',cxDateEdit1.Date)+''' and PARTID in (select bmbh from RES_DEPARTMENT where fzr='+ QuotedStr(_UserName)+') ' );
qry_search.Open;
if qry_search.RecordCount=0 then
begin
MessageDlg('查詢提示:沒有找到符合查詢條件(或當前用戶權限)的記錄!',mtWarning,[mbOK],0);
Exit;
end;
end;
if (Trim(cxTextEdit3.Text)<>'') and (Trim(cxDateEdit1.Text)<>'') then
begin
qry_search.Close;
qry_search.SQL.Clear;
qry_search.SQL.Add( ' select * from RES_HR_RSJS where GH='''+ Trim(cxTextEdit3.Text)+''' and SXRQ='''+ FormatDateTime('yyyy/mm/dd',cxDateEdit1.Date)+''' and PARTID in (select bmbh from RES_DEPARTMENT where fzr='+ QuotedStr(_UserName)+') ' );
qry_search.Open;
if qry_search.RecordCount=0 then
begin
MessageDlg('查詢提示:沒有找到符合查詢條件(或當前用戶權限)的記錄!',mtWarning,[mbOK],0);
Exit;
end;
end;
end;
str:string = ' select YZFL from DB_InDetail where YZFL =%s and flag=1 ';
var
s:string;
begin
s := Format(str,[Quostrd(Trim(ComboBox1.Text))]);
with adoquery2 do
begin
close;
sql.clear;
sql.add(s);
open;
end;
end;