关于SQL多条件查询的问题:急。。。。。。(50分)

  • 主题发起人 主题发起人 kk2000
  • 开始时间 开始时间
K

kk2000

Unregistered / Unconfirmed
GUEST, unregistred user!
我以前就是用这种方法实现多条件查询的,而现在却不行我觉得奇怪。小弟只好让
各位富翁帮我看一下50分,OK!!!
运行时说“LIKE”附近有误,可我看不出来有劳各位啦,代码如下:
(注数据库是 sql server 7.0 字段为VARCHAR类型)
var
Form5: TForm5;
function get_ypqm:string;
function get_sccj:string;
function get_jx:string;
function get_ypgg:string;
implementation
uses U_dm,U_ypxx;
{$R *.DFM}
function get_ypqm:string;
var
str,temp:string;
begin
str:='ypqm like ''%'+trim(form5.Edit1.text)+'%''';
if trim(form5.Edit1.Text)='' then
temp:=''
else
temp:=str;
result:=temp;
end;
function get_sccj:string;
var
str,temp:string;
begin
str:='sccj like ''%'+trim(form5.edit3.text)+'%''';
if trim(form5.Edit3.Text)='' then
temp:=get_ypqm
else if get_ypqm='' then
temp:=str
else
temp:=get_ypqm + ' and ' + str;
result:=temp;
end;
function get_jx:string;
var
str,temp:string;
begin
str:='jx like ''%'+trim(form5.combobox1.text)+'%''';
if trim(form5.ComboBox1.Text)='' then
temp:=get_sccj
else if get_sccj='' then
temp:=str
else
temp:=get_sccj + ' and ' + str;
result:=temp;
end;
function get_ypgg:string;
var
str,temp:string;
begin
str:='ypgg like ''%'+trim(form5.edit7.text)+'%''';
if trim(form5.Edit7.Text)='' then
temp:=get_jx
else if get_jx='' then
temp:=str
else
temp:=get_jx + ' and ' + str;
result:=temp;
end;
procedure TForm5.BitBtn1Click(Sender: TObject);
var
str:string;
I,N:integer;
begin
dm.ADOQypcx.Connection:=dm.ADOCnn;
if get_ypgg='' then
str:=''
else
str:='where' + get_ypgg;
dm.ADOQypcx.Close;
dm.ADOQypcx.SQL.Clear;
dm.ADOQypcx.SQL.Add('select * from ypxxjlb' + str );
dm.ADOQypcx.Open;
I:=1;
dm.ADOQypcx.First;
while not dm.ADOQypcx.Eof do
begin
form2.StringGrid1.Cells[0,0]:=inttostr(I);
form2.StringGrid1.Cells[1,I]:=dm.ADOQypcx['ypqm'];
form2.StringGrid1.Cells[2,I]:=dm.ADOQypcx['yptm'];
form2.StringGrid1.Cells[3,I]:=dm.adoqypcx['jc'];
form2.StringGrid1.Cells[4,I]:=dm.ADOQypcx['ypgg'];
form2.StringGrid1.Cells[5,I]:=dm.ADOQypxx['bzwh'];
form2.StringGrid1.Cells[6,I]:=dm.ADOQypcx['jx'];
form2.StringGrid1.Cells[7,I]:=dm.ADOQypcx['zcsb'];
form2.StringGrid1.Cells[8,I]:=dm.ADOQypcx['sccj'];
form2.StringGrid1.Cells[9,I]:=dm.ADOQypcx['jbdwx'];
form2.StringGrid1.Cells[10,I]:=dm.ADOQypcx['zjdwd'];
form2.StringGrid1.Cells[11,I]:=inttostr(dm.ADOQypcx['dwhsbl']);
form2.StringGrid1.Cells[12,I]:=inttostr(dm.ADOQypcx['yxrqy']);
form2.StringGrid1.Cells[13,I]:=inttostr(dm.adoqypcx['yxrqr']);
inc(I);
dm.ADOQypcx.Next;
end;
form5.ModalResult:=MROK;
end;
 
你最好是在调试时把拼成的SQL语句copy出来放到SQL7的SQL查询分析器里运行,
那样很多错误一眼就看出来了,估计是单引号等的问题。
 
》》if get_ypgg='' then
str:=''
else
str:='where' + get_ypgg;
where 的后面加上空格,看看,不行的话用SQL Monitor跟踪一下sql
 
该问题已经得到解决,谢谢各位啦!
 

Similar threads

后退
顶部