我的"物料编码"分为十大类例:A类,B类,C类.........J类.在生成编码时,有六位数字,例A1000001,B1000002,B10000003,C100004,意思就是编码最前面的那个字母是用来识别物料类别的.后面的六位数字是用来编号的.目地:后面的六位数按顺续足个增加,最前面的那个字母根据你所选的物料类型自动变化的.
问题:
当物料编码,有A100001,B100002,A1000003时,我用SQL.Add('select max(物料编码) as ss From clzl ')取最大值,最取到的最大值是B100002,而不是A100003,所以后面六位数没法再编下去了.
所以想请叫:在SQL语句里是否可以加一个结取函数,只取后六位,那MAX就可以确定最大值了.请叫了.再请叫有没有其它办法?
var
s,m: String;
i: integer;
begin
s:='A100';
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select max(物料编码) as ss From clzl ');
Open;
SHOWMESSAGE(trim(QUERY1.FIELDBYNAME('ss').Value));
end;
If Query1.FieldByName('ss').Value = null then
s := s + '001'
else
begin
m:= Trim(Query1.FieldByName('ss').Value) ;
i:= StrToInt(Trim(Copy(m,3,6))) ;
SHOWMESSAGE(INTTOSTR(i));
if i<99999 then
s:= s + '00'+ InttoStr(i +1)
else if i<10000 then
s:= s + '0'+ InttoStr(i +1)
else
s:= s +InttoStr(i +1);
end;
edit1.Text:= s;
end;
问题:
当物料编码,有A100001,B100002,A1000003时,我用SQL.Add('select max(物料编码) as ss From clzl ')取最大值,最取到的最大值是B100002,而不是A100003,所以后面六位数没法再编下去了.
所以想请叫:在SQL语句里是否可以加一个结取函数,只取后六位,那MAX就可以确定最大值了.请叫了.再请叫有没有其它办法?
var
s,m: String;
i: integer;
begin
s:='A100';
With Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select max(物料编码) as ss From clzl ');
Open;
SHOWMESSAGE(trim(QUERY1.FIELDBYNAME('ss').Value));
end;
If Query1.FieldByName('ss').Value = null then
s := s + '001'
else
begin
m:= Trim(Query1.FieldByName('ss').Value) ;
i:= StrToInt(Trim(Copy(m,3,6))) ;
SHOWMESSAGE(INTTOSTR(i));
if i<99999 then
s:= s + '00'+ InttoStr(i +1)
else if i<10000 then
s:= s + '0'+ InttoStr(i +1)
else
s:= s +InttoStr(i +1);
end;
edit1.Text:= s;
end;
啊,对了,substring出来的是字符型,可能出问题,你用convert()或者cast()转换为数字即可