var
s,id,k,k1,k2,max1:string;
lint_maxvalue:integer;
begin
table1.open;
k:=formatdatetime('eeee',now);
k1:=formatdatetime('d',now);
k2:=formatdatetime('m',now);
if (strtoint(k2)>1) and (strtoint(k2)<10) then
begin
k:=k+'0'+k2
end
else
k:=k+k2;
if (strtoint(k1)>1) and (strtoint(k1)<10) then
begin
k:=k+k1;
end
else
k:=k+k1;
query2.close;
query2.SQL.Clear;
query2.SQL.add('select max(Tkey_field) as maxvalue1 from Tkey');
query2.open;
s:=s+'select '+(copy(query2.Fieldbyname('maxvalue1').asstring,9,4))+' as maxvalue';
s:=s+' from Tkey where '+copy(query2.Fieldbyname('maxvalue1').asstring,1,8)+'='+''''+k+'''';
query1.close;
query1.SQL.Clear;
query1.SQL.add(s);
query1.Open;
if query1.Recordcount=0 then
begin
application.MessageBox('ss','sfdasdfsdf',mb_ok);
id:=k+'0001';
end
else
if inttostr(query1.FieldByName('maxvalue').AsInteger)='' then
begin
id:=k+'0001'
end
else
Lint_maxvalue:=query1.FieldValues['maxvalue']+1;
if Lint_maxvalue<10 then
begin
id:=k+'000'+inttostr(Lint_maxvalue);
end
else
if (Lint_maxvalue>=10) and (Lint_maxvalue<100) then
begin
id:=k+'00'+inttostr(Lint_maxvalue);
end
else
if (Lint_maxvalue>=100) and (Lint_maxvalue<1000) then
begin
id:=k+'0'+inttostr(Lint_maxvalue);
end;
label1.Caption:=id;
table1.Append;
table1.edit;
table1.FieldByName('Tkey_field').Asstring:=id;
table1.Post;
系统提示select包含一个名留子,拼写错误或丢失的参数,或标点符号不正确。请帮我解决一下。
參考答案:query2.open;
s:=s+'select '+(copy(query2.Fieldbyname('maxvalue1').asstring,9,4))+' as maxvalue';
这里是不是没有给s赋初值啊?
改成:
query2.open;
s:="";
s:=s+'select '+(copy(query2.Fieldbyname('maxvalue1').asstring,9,4))+' as maxvalue';