//SQL语句
select * into #xmtemp from xm2002 where month(yeam)='9'
and xmbh not in (select xmbh from xm2002 where month(yeam)='10') //通过
//变量代入出现问题
procedure Tform1.Button1Click(Sender: TObject);
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * into xmtemp from xm2002 where month(yeam)='+''''+inttostr(monthof(datetimepicker1.datetime))+'''') ;//正确
sql.add('and xmbh not in(select xmbh from xm2002 where month(yeam)='+''''+inttostr(monthof(datetimepicker2.datetime))+'''') ;//出错
execsql;
showmessage('ok');
end;
end;
出错提示:unclosed quotation before the character string '10''
//具体成数字是正确的
procedure TForm1.Button1Click(Sender: TObject);
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * into #xmtemp from xm2002 where month(yeam)=''9''') ;
sql.add('and xmbh not in(select xmbh from xm2002 where month(yeam)=''10'')') ;
execsql;
showmessage('ok');
end;
end;
select * into #xmtemp from xm2002 where month(yeam)='9'
and xmbh not in (select xmbh from xm2002 where month(yeam)='10') //通过
//变量代入出现问题
procedure Tform1.Button1Click(Sender: TObject);
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * into xmtemp from xm2002 where month(yeam)='+''''+inttostr(monthof(datetimepicker1.datetime))+'''') ;//正确
sql.add('and xmbh not in(select xmbh from xm2002 where month(yeam)='+''''+inttostr(monthof(datetimepicker2.datetime))+'''') ;//出错
execsql;
showmessage('ok');
end;
end;
出错提示:unclosed quotation before the character string '10''
//具体成数字是正确的
procedure TForm1.Button1Click(Sender: TObject);
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * into #xmtemp from xm2002 where month(yeam)=''9''') ;
sql.add('and xmbh not in(select xmbh from xm2002 where month(yeam)=''10'')') ;
execsql;
showmessage('ok');
end;
end;
and xmbh not in (select xmbh from xm2002 where month(yeam)='10')怎么写成DELPHI里的语句?
'''9'''
在DELPHI中'''等于'
少了一个右括号。 ~~这少
sql.add(' and xmbh not in(select xmbh from xm2002 where month(yeam)='+''''+inttostr(monthof(datetimepicker2.datetime))+'''')
month(yeam)='+''''+inttostr(monthof(datetimepicker2.datetime))
+'''')
~~~~~这写错了,该这么写''')'
')
~~~ 还少了一个右括号和一个单引号。表示这个add方法结束
这样写太不容易看清了,还不如用一个字符串变量先保存再add呢
tempsql:='and xmbh not in(select xmbh from xm2002 where
month(yeam)='+''''+inttostr(monthof(datetimepicker2.datetime))+''') ';
sql.add(tempsql);
month(yeam)='+''''+inttostr(monthof(datetimepicker2.datetime))
+'''')
~~~~~这写错了,该这么写''')' 为什么是这么写?没看懂