在新增加记录时
要求自动生成6位整形ID 123456
12位表示年份,34位表示类型(自己定义),56位表示流水号(自动生成,累加)12年份根据输入时间自动生成,类型根据在添加记录时选择的类型自动生成,
流水号,如果前面4位代码相同自动增加1,没有相同的则从01开始记数。
如果生成的要求是字符形又该怎么做?如果要求的是16位字符形
前2位是类型(为英文字母),后面分别是年份,类型,流水号。
该怎么做?急啊。各位兄弟姐妹帮帮忙吧。最好给个例子!
要求自动生成6位整形ID 123456
12位表示年份,34位表示类型(自己定义),56位表示流水号(自动生成,累加)12年份根据输入时间自动生成,类型根据在添加记录时选择的类型自动生成,
流水号,如果前面4位代码相同自动增加1,没有相同的则从01开始记数。
如果生成的要求是字符形又该怎么做?如果要求的是16位字符形
前2位是类型(为英文字母),后面分别是年份,类型,流水号。
该怎么做?急啊。各位兄弟姐妹帮帮忙吧。最好给个例子!
解决方案 »
- WM_DEVICECHANGE消息处理的问题
- API中的LARGE_INTEGER 在delphi中是什么类型??
- 紧急求助 "EhLib 的函数集可以从 Text以及其内部格式的数据导入到DBGridEh的数据集中"具体是怎么操作的,有人知道嘛
- TWebBrowser问题
- FastReport中的总页数【TotalPages】为什么总是0?
- 怎么控制不让输入一些字符
- 怎样在报表中金额中加Y如30.00Y
- 急救,在线等候!delphi怎么实现可以在word里面通用的报表??高分
- 请教一个关于主从表的问题?
- delphi有没有SNMP的控件
- 请问熟悉POS系统的朋友
- 谢谢Delphi版各位的支持与理解!!!
AS --------------------生成配件編號
declare @mat_no varchar(10),@no int,@mat1 varchar(3)
declare @year varchar(2)
set @year=datepart(yy,getdate())
if (select count(*) from ha_mat where mata_no=@mata_no)<1
begin
set @mat_no_auto=@year+@mata_no+'01'
return
end
select top 1 @mat_no=isnull(mat_no,@mata_no+'00') from ha_mat where mata_no=@mata_no order by mat_no desc
set @mat1=substring(@mat_no,5,2)
set @no=convert(int,@mat1)+1
if @no>=100
begin
set @mat_no_auto='0'
return
end
set @mat1=convert(varchar(2),@no)
while len(@mat1)<2
set @mat1='0'+@mat1
set @mat_no_auto=@mata_no+@mat1GO
var
i,j,m:integer;
year,month,day:word;
y,v,s,id:string;
begin
m:=0;
decodedate(now,year,month,day);
v:='fd'; ————————定义的变量类型,自己选
y:=copy(inttostr(year),3,2);————代表年份的
form1.Table1.Open;
form1.Table1.First;
i:=form1.Table1.RecordCount;
if i>0 then
begin
for j:=0 to i-1 do
begin
s:=form1.Table1.FieldValues['id'];
if copy(s,1,4)=y+v then
m:=m+1;
end;
if m=0 then
id:=y+v+'01'————最终的id
else
begin
m:=m+1;
if m<10 then
id:=y+v+'0'+inttostr(m)
else
id:=y+v+inttostr(m);
end;
end
else
id:=y+v+'01';
end;
declare @a2 char(2)--中间2位
select @a1 = datepart(yy,getdate())--得到前两位
select @a2 = '34'--中间2位推出id的sql语句如下
select (cast((@a1+@a2) as integer)*100 + IsNUll(max(id mod 100), 0 ) from table where id like @a1+@a2
bbs791109(小别) ,lovelymelon(小人物) , firetoucher(风焱)
小弟是处学者
对DELPHI的语法也不太熟。
刚看了COPY的函数。
麻烦哪位解释一下吧。特别是Index, Count,我不太明白。以下为原文Delphi syntax:function Copy(S; Index, Count: Integer): string;
function Copy(S; Index, Count: Integer): array;DescriptionS is an expression of a string or dynamic-array type. Index and Count are integer-type expressions. Copy returns a substring or subarray containing Count characters or elements starting at S[Index]. The substring or subarray is a unique copy (that is, it does not share memory with S, although if the elements of the array are pointers or objects, these are not copied as well.)If Index is larger than the length of S, Copy returns an empty string or array.If Count specifies more characters or array elements than are available, only the characters or elements from S[Index] to the end of S are returned.Note: When S is a dynamic array, you can omit the Index and Count parameters and Copy copies the entire array.
S:要拷贝的串,Index:要拷贝的开始位置,Count:要拷贝几个字符
example:
var
s,s1:string;
begin
s:='123456';
s1:=Copy(s,1,3);
PrintLn(s1);
end;
结果是:123
var
i,j,m:integer;
year,month,day:word;
y,v,s,id:string;
begin
m:=0;
decodedate(now,year,month,day);
v:='fd'; ————————定义的变量类型,自己选
y:=copy(inttostr(year),3,2);————代表年份的
form1.Table1.Open;
form1.Table1.First;
i:=form1.Table1.RecordCount;
if i>0 then
begin
for j:=0 to i-1 do
begin
s:=form1.Table1.FieldValues['id'];
if copy(s,1,4)=y+v then
m:=m+1;
end;
if m=0 then
id:=y+v+'01'————最终的id
else
begin
m:=m+1;
if m<10 then
id:=y+v+'0'+inttostr(m)
else
id:=y+v+inttostr(m);
end;
end
else
id:=y+v+'01';
end;
我也这么实现。利用存储过程,设置输入输出参数,用sql语句实现编号。这样确实可以避免因为多客户机同时增ID时的ID重复问题。
原来使用的一个存储过程实例:CREATE PROCEDURE [dbo].[GetCode]
@begincode char(8),
@ReturnCode char(12) OUTPUT
AS
if (select count(*) from ceshiMaster where bill_code like @begincode+'%')>0
begin
select @ReturnCode=Max(bill_code) from ceshimaster
where bill_code like @begincode+'%'
set @ReturnCode=right(@ReturnCode,4)+1
set @ReturnCode=@begincode+@ReturnCode
end
else
SET @ReturnCode=@begincode+'1000'GO
认为lovelymelon(小人物)的办法比较易懂。
但是他是用table组件做的,有没有办法用adoquery
里的sql语句来做。
因为我的这个程序是在查询的结果里添加
只能用query