高手过来看看,这个SQL语句有什么问题?(100分)

  • 主题发起人 主题发起人 yangjj
  • 开始时间 开始时间
Y

yangjj

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure Tjh_fpprint1.SpeedButton1Click(Sender: TObject);
begin
if LCb1.text<>'' then begin
jh_fpb1.adoquery2.sql.clear;
jh_fpb1.adoquery2.sql.add('SELECT jh_zb.jh_code, jh_zb.gc_name,
jh_zb.zj_kind, jh_zb.xm_code, jh_zb.ys_bank, jh_zb.jh_data,
jh_zb.dw_uint, jh_zb.pz_file, jh_zb.bb_unit, jh_zb.jb_person,
jh_zb.bz_data, jh_zb.bz_memo, jh_fb.sb_code, jh_fb.sb_name,
jh_fb.gg_type,jh_fb.jl_unit, jh_fb.sl_amount, jh_fb.dj_price,
jh_fb.je_sum, jh_fb.gh_unit, jh_fb.jh_person, jh_fb.bz_memo1
FROM jh_zb LEFT JOIN jh_fb ON jh_zb.jh_code = jh_fb.jh_code
where jh_zb.code='''+ E1.text + ''' and jh_fb.jh_person='''+lcb1.text+''' order by jh_fb.sb_code ASC');
jh_fpb1.adoquery2.open;

end;

end;
出现如下提示:
[Error] jh_fpprint.pas(53): Unterminated string
[Error] jh_fpprint.pas(54): ')' expected but identifier 'jh_zb' found
[Error] jh_fpprint.pas(54): 'END' expected but ',' found
[Error] jh_fpprint.pas(60): Unterminated string
[Error] jh_fpprint.pas(65): '.' expected but ';' found
[Fatal Error] jh_fpb.pas(95): Could not compile used unit 'jh_fpprint.pas'
帮帮忙吧!,我很着急!

 
>> where jh_zb.code='''+ E1.text + ''' and jh_fb.jh_person='''+lcb1.text+''' order by jh_fb.sb_code ASC');
改为:
where jh_zb.code=#39+ E1.text + #39+' and jh_fb.jh_person='+ #39 +lcb1.text+#39+' order by jh_fb.sb_code ASC');
 
if LCb1.text<>'' then begin
jh_fpb1.adoquery2.sql.clear;
jh_fpb1.adoquery2.sql.add('SELECT jh_zb.jh_code, jh_zb.gc_name,
add('jh_fpb1.adoquery2.sql.add('jh_zb.zj_kind, jh_zb.xm_code, jh_zb.ys_bank, jh_zb.jh_data,') ;
add('jh_zb.dw_uint, jh_zb.pz_file, jh_zb.bb_unit, jh_zb.jb_person, ');
add('jh_zb.bz_data, jh_zb.bz_memo, jh_fb.sb_code, jh_fb.sb_name, ');
add('jh_fb.gg_type,jh_fb.jl_unit, jh_fb.sl_amount, jh_fb.dj_price,');
add('jh_fb.je_sum, jh_fb.gh_unit, jh_fb.jh_person, jh_fb.bz_memo1');
FROM jh_zb LEFT JOIN jh_fb ON jh_zb.jh_code = jh_fb.jh_code');
where jh_zb.code='''+ E1.text + ''' and jh_fb.jh_person='''+lcb1.text+''' order by jh_fb.sb_code ASC');
jh_fpb1.adoquery2.open;

这样是是,if jh_zb.code is integer then
begin
jh_zb.code=+ E1.text +
if jh_fb.jh_person=integer then
jh_fb.jh_person=+lcb1.text+

end;
 
to zhihuali:这样还是不对,仍然出现错误!
Error] jh_fpprint.pas(53): Unterminated string
[Error] jh_fpprint.pas(54): ')' expected but identifier 'jh_zb' found
[Error] jh_fpprint.pas(54): 'END' expected but ',' found
[Error] jh_fpprint.pas(60): Unterminated string
[Error] jh_fpprint.pas(65): '.' expected but ';' found
[Fatal Error] jh_fpb.pas(95): Could not compile used unit 'jh_fpprint.pas'
 
SQL语句是字符串,请注意变量与字符串的连接,如下是一个例子,请参考:
Query1.SQL.Clear;
Query1.SQL.Add('Select * From Orders Where OrderOn = '''+Edit1.Text+'''');
请特别注意语句中的单引号个数。
 
procedure Tjh_fpprint1.SpeedButton1Click(Sender: TObject);
var
SQLStr:String;
begin
if trim(LCb1.text)<>'' then
begin
with jh_fpb1.adoquery2 do
begin
Close;
SQL.Clear;
SQLStr:='SELECT jh_zb.jh_code, jh_zb.gc_name,jh_zb.zj_kind, jh_zb.xm_code,'+
'jh_zb.ys_bank, jh_zb.jh_data, jh_zb.dw_uint, jh_zb.pz_file,'+
'jh_zb.bb_unit, jh_zb.jb_person,jh_zb.bz_data, jh_zb.bz_memo,'+
'jh_fb.sb_code, jh_fb.sb_name, jh_fb.gg_type,jh_fb.jl_unit, '+
'jh_fb.sl_amount, jh_fb.dj_price, jh_fb.je_sum, jh_fb.gh_unit,'+
'jh_fb.jh_person, jh_fb.bz_memo1 '+
'FROM jh_zb LEFT JOIN jh_fb ON jh_zb.jh_code = jh_fb.jh_code '+
'where jh_zb.code='+#39+ E1.text + #39+' and jh_fb.jh_person='+ #39 +
lcb1.text+#39+' order by jh_fb.sb_code ASC';
SQL.Add(SQLStr);
Open;
end;
end;
end;
 
to zhihuali:
还是有问题!在运行时提示“变量jh_zb.jh_code没有默认值”
但应该是有默认值的呀!
 
ren "变量jh_zb.jh_code没有默认值" 看看此字段是否为非空字段。
 
此字段不是非空字段!与这个有关系吗?
 
难道没有人知道是什么原因吗?
 
jh_zb.code你这个字段是什么类型,如果是数值型,请不要为它加单引号!
 
procedure Tjh_fpprint1.SpeedButton1Click(Sender: TObject);
begin
if LCb1.text<>'' then begin
jh_fpb1.adoquery2.sql.clear;
jh_fpb1.adoquery2.sql.add('SELECT jh_zb.jh_code, jh_zb.gc_name,'+
'jh_zb.zj_kind, jh_zb.xm_code, jh_zb.ys_bank, jh_zb.jh_data,'+
'jh_zb.dw_uint, jh_zb.pz_file, jh_zb.bb_unit, jh_zb.jb_person,'+
'jh_zb.bz_data, jh_zb.bz_memo, jh_fb.sb_code, jh_fb.sb_name,'+
'jh_fb.gg_type,jh_fb.jl_unit, jh_fb.sl_amount, jh_fb.dj_price,'+
'jh_fb.je_sum, jh_fb.gh_unit, jh_fb.jh_person, jh_fb.bz_memo1 '+
'FROM jh_zb LEFT JOIN jh_fb ON jh_zb.jh_code = jh_fb.jh_code '+
'where jh_zb.code='''+ E1.text + ''' and jh_fb.jh_person='''+lcb1.text+''' order by jh_fb.sb_code ASC');
jh_fpb1.adoquery2.open;

end;

end;
 
可能是此句DELPHI语句太长,或是'或)用了全角字符才会出现所示错误,如果是SQL本身的
错误,应在OPEN语句处出错
请改成如下格式,再编译,看ERROR在哪一行上。如果编译无ERROE,在运行时出错,在
OPEN前加上显示此QUERY的SQL语句,先看语句是否对。
procedure Tjh_fpprint1.SpeedButton1Click(Sender: TObject);
begin
if LCb1.text<>'' then
begin
with jh_fpb1.adoquery2 do
begin
if active then
close;
sql.clear;
sql.add('SELECT jh_zb.jh_code, jh_zb.gc_name,');
sql.add('jh_zb.zj_kind, jh_zb.xm_code, jh_zb.ys_bank, jh_zb.jh_data,');
sql.add('jh_zb.dw_uint, jh_zb.pz_file, jh_zb.bb_unit, jh_zb.jb_person,');
sql.add('jh_zb.bz_data, jh_zb.bz_memo, jh_fb.sb_code, jh_fb.sb_name, ');
sql.add('jh_fb.gg_type,jh_fb.jl_unit, jh_fb.sl_amount, jh_fb.dj_price,');
sql.add('jh_fb.je_sum, jh_fb.gh_unit, jh_fb.jh_person, jh_fb.bz_memo1 ');
sql.add('FROM jh_zb LEFT JOIN jh_fb ON jh_zb.jh_code = jh_fb.jh_code');
sql.add(' where jh_zb.code='''+ E1.text + ''' and jh_fb.jh_person='''+lcb1.text+''' order by jh_fb.sb_code ASC');
// showmessage(sql.text);
try
open;
except
raise;
end;
end;
end;

end;

 
to 风中流云。出现的错误和最上面的一样!
 
完整复制,粘贴
if LCb1.text <> '' then
begin
jh_fpb1.adoquery2.sql.clear;
jh_fpb1.adoquery2.sql.text := 'SELECT jh_zb.jh_code, jh_zb.gc_name,'#13#10+
'jh_zb.zj_kind, jh_zb.xm_code, jh_zb.ys_bank, jh_zb.jh_data,'#13#10+
'jh_zb.dw_uint, jh_zb.pz_file, jh_zb.bb_unit, jh_zb.jb_person,'#13#10+
'jh_zb.bz_data, jh_zb.bz_memo, jh_fb.sb_code, jh_fb.sb_name,'#13#10+
'jh_fb.gg_type, jh_fb.jl_unit, jh_fb.sl_amount, jh_fb.dj_price,'#13#10+
'jh_fb.je_sum, jh_fb.gh_unit, jh_fb.jh_person, jh_fb.bz_memo1'#13#10+
'FROM jh_zb LEFT JOIN jh_fb on jh_zb.jh_code = jh_fb.jh_code'#13#10+
'where jh_zb.code = '''+E1.text + ''' and jh_fb.jh_person = '''+lcb1.text+''' order by jh_fb.sb_code ASC';
jh_fpb1.adoquery2.open;
end;
 
你要是死了就是苯死的!
 
to NoSwing:你是不是比尔二世?那么聪明还来大富翁干什么?
 
aspire的答案完全正确
 
改为:
where jh_zb.code='+''''+ E1.text + ''''+' and jh_fb.jh_person=''''+lcb1.text+''''+' order by jh_fb.sb_code ASC');
jh_fpb1.adoquery2.open;
 
to aspire:还是出现“变量jh_zb.jh_code没有默认值”的提示!
 
后退
顶部