我想做一个查询,一个条件是模糊查询,可以输入‘工号’‘姓名’‘部门’,另一个条件是月份。意思是某个月份某个工号的查询,某个月份某个部门的查询,某个月份某个姓名的查询,我自己写的代码达不到着种效果。procedure TForm7.Button1Click(Sender: TObject);
begin
adoquery1.Close;
adoquery1.SQL.clear;
adoquery1.SQL.Add('select * from 工资管理 where (工号 like '+QuotedStr('%'+edit1.text+'%')+' or 姓名 like '+QuotedStr('%'+edit1.text+'%')+' or 部门 like'+QuotedStr('%'+edit1.text+'%')+') and 月份='''+formatdatetime('yyyy-mm',datetimepicker1.date)+'''');
adoquery1.open;
end;
begin
adoquery1.Close;
adoquery1.SQL.clear;
adoquery1.SQL.Add('select * from 工资管理 where (工号 like '+QuotedStr('%'+edit1.text+'%')+' or 姓名 like '+QuotedStr('%'+edit1.text+'%')+' or 部门 like'+QuotedStr('%'+edit1.text+'%')+') and 月份='''+formatdatetime('yyyy-mm',datetimepicker1.date)+'''');
adoquery1.open;
end;
解决方案 »
- delphi 中的Internal Error: C1632
- 怎么在程序运行的时候出现和DELPHI下一样的调试信息???
- RxRichEdit1 里面插入文本文件问题
- VPN 网络编程 先谢谢
- 那请问,把integer型参数,转成string型,用什么函数?
- 很急的问题。请高手们不吝赐教!!!!分不够可以再加!!!来者有分!!!
- delphi怎样调用外部程序?? 如 Regsvr32.exe
- 关于DLL调试的问题
- 请教大侠,如何使子窗体左上图标和主窗体一致呢?
- 哪位高手能告诉我delphi连接sql server的所有方法,谢谢!!!
- 散分二
- ADOQuery执行多个MySQL的语句问题,在线等,急!
部門+月份
工號+月份??
還是 (姓名 or 部門 or 工號 ) and 月份
create procedure GetQueryData
@workno VARCHAR(50),
@workname VARCHAR(50),
@workdept VARCHAR(50),
@workdate DATETIME,
@QueryType int
as
if @QueryType=1
begin
select * from table3 where workno=@workno and workdate=@workdate
end
if @QueryType=2
begin
select * from table3 where workname=@workname and workdate=@workdate
end
if @QueryType=3
begin
select * from table3 where workdept=@workdept and workdate=@workdate
end
MSSQL中创建以上存储过程,然后调用,里面很多细节处理我忽略了
那就簡單了,你應該還會一個 Combobox 來做對應的,比如 combobox 選擇部門,那麼後面的值就對應就是查部門的。我記得我上次幫你寫過。
var
vSQL : String;case combobox.itemindex of
0: vSQL := ' 工号 like '+QuotedStr('%'+edit1.text+'%');
1: vSQL := ' 姓名 like '+QuotedStr('%'+edit1.text+'%');
2: vSQL := ' 部门 like '+QuotedStr('%'+edit1.text+'%');
end;vSQL := 'select * from 工资管理 where 月份= Quotedstr(formatdatetime('yyyy-mm',datetimepicker1.date))+vSQL;
adoquery1.Close;
adoquery1.SQL.clear;
adoquery1.SQL.text := vSQL ;
adoquery1.open;
+ ' pl.mid,pl.manuid,pl.trade,'
+ ' pl.permission,permissonExpdate,Barcode,pl.country,pl.firstindate,'
+ ' pl.lastincost,pl.useing as useing2,pl.QAPass,pl.QADate,pl.SaleRegion,'
+ ' sp.PlanPrice,sp.moveprice FROM PROD AS A left JOIN salePRICE as sp ON A.id=sp.prodid left join prodsuppl as pl on a.id=pl.prodid '
+ ' left join suppliers as mi on pl.Manuid = mi.Manuer '
+ ' where ((A.CODE like ''%''+'+quotedstr(trim(ParaItemsIn[2]))+' ) OR '
+ '(A.PYM LIKE ''%''+'+quotedstr(trim(ParaItemsIn[2])) +'+''%'')) or '
+ '(pl.barcode like '+ quotedstr(trim(ParaItemsIn[2]))+')';
我这个应该跟你的差不多。。
vSQL : String;case combobox.itemindex of
0: vSQL := ' 工号 like '+QuotedStr('%'+edit1.text+'%');
1: vSQL := ' 姓名 like '+QuotedStr('%'+edit1.text+'%');
2: vSQL := ' 部门 like '+QuotedStr('%'+edit1.text+'%');
end;vSQL := 'select * from 工资管理 where 月份= '+ Quotedstr(formatdatetime('yyyy-mm',datetimepicker1.date))+vSQL;
adoquery1.Close;
adoquery1.SQL.clear;
adoquery1.SQL.text := vSQL ;
adoquery1.open;
看一下你執行時的SQL語句是什麽?然後在查詢分析器中執行一下看是什麽結果.
呵呵,我不太理解。。 你的是兩個EDIT,怎麼實現四個條件的輸入呢?? 我的腦子反應越來越慢了。
begin
qry1.Close;
qry1.SQL.Text:='select * from tb1 where ((bm like '+QuotedStr('%'+Edit2.Text+'%')+')or(name like '+QuotedStr('%'+Edit2.Text+'%')+')or(id like '+QuotedStr('%'+Edit2.Text+'%')+')) and dj='''+edit3.Text+'''';
qry1.open;
end;注意:((bm like '+QuotedStr('%'+Edit2.Text+'%')+')or(name like '+QuotedStr('%'+Edit2.Text+'%')+')or(id like '+QuotedStr('%'+Edit2.Text+'%')+'))多加了一个括号。