bsp; str,s:string;
begin
s:='';//S变量用于生成查询的条件,即用and连接的各个查询条件
if e_name.Text<>'' then
s:='病人姓名 like '''+'%'+e_name.text+'%'+'''';
//若“姓名”文本框中有内容,则将“病人姓名 like 文本框中内容”连接到S中
if (s<>'') and (e_s.Text<>'') then
s:=s+' and 科别 like '''+'%'+e_s.text+'%'+''''
//若S变量和“科别”文本框均不为空,则将“and 科别 like 文本框中内容”连接到S中
else if e_s.text<>'' then
s:=' 科别 like '''+'%'+e_s.Text+'%'+'''';
//若S变量为空,“科别”文本框非空,则将“科别 like 文本框中内容”连接到S中
if (s<>'') and (e_pnum.Text<>'') then
s:=s+' and 住院号 like '''+'%'+e_pnum.text+'%'+''''
// 若S变量和“住院号”文本框均不为空,则将“and 住院号 like 文本框中内容”连接到S中
else if e_pnum.text<>'' then
s:=' 住院号 like '''+'%'+e_pnum.Text+'%'+'''';
//若S变量为空,“住院号”文本框非空,则将“住院号 like 文本框中内容”连接到S中
if (s<>'') and (e_num.Text<>'') then
s:=s+' and 身份证 like '''+'%'+e_num.text+'%'+''''
// 若S变量和“身份证”文本框均不为空,则将“and 身份证 like 文本框中内容”连接到S中
else if e_num.text<>'' then
s:=' 身份证 like '''+'%'+e_num.Text+'%'+'''';
//若S变量为空,“身份证”文本框非空,则将“身份证 like 文本框中内容”连接到S中
adoquery1.close;
adoquery1.sql.clear;
//生成SQL查询语句,并添加到adoquery1组件的SQL特性中
str:='select * from patient where '+s;
adoquery1.sql.add(str);
//打开指定的数据表patient,执行SQL查询语名
adoquery1.Open;
end;