1.按电脑日期自动编号的生成:生成示例:CK201003010001
单机版:
SELECT 'CK' & year(date()) & right('0' & month(date()),2) & right('0' & day(date()),2) & iif(A.ID is null,'0001',right('0000' & A.ID,4))
as 单号
from (SELECT max(right(出库登记表.单号,4)) +1 as ID FROM 出库登记表 where left(出库登记表.单号,10)='CK' & year(date()) & right('0' & month(date()),2) & right('0' & day(date()),2)) AS A
网络版:
SELECT 'CK' + cast(year(getdate()) as varchar(4))+right(100 + month(getdate()),2)+right(100 + day(getdate()),2)+right(str(10000 + (case when A.ID is null then '1' else A.ID end)),4)
as 单号
FROM (SELECT cast(right(max(出库登记表.单号),4) as int)+1 as ID FROM出库登记表where left(出库登记表.单号,10)= 'CK' + cast(year(getdate()) as varchar(4)) + right('0' + cast(month(getdate()) as varchar(2)),2)+ right('0' + cast(day(getdate()) as varchar(2)),2)) AS A
2.按设置日期自动编号的生成 : 生成示例:RK201003010001
单机版:
SELECT "RK" & year(#:入库日期#) & right('0' & month(#:入库日期#),2) & right('0' & day(#:入库日期#),2) & iif(A.ID is null,'0001',right('0000' & A.ID,4))
as入库单编号
FROM (SELECT max(right(入库.入库单编号,4))+1 AS ID FROM 入库 where 入库日期=#:入库日期#) AS A
网络版:
SELECT 'RK' + cast(year(':入库日期') as varchar(4)) +right(100 + month(':入库日期'),2) +right(100 + day(':入库日期'),2) + right(str(10000 + (case when A.ID is null then '1' else A.ID end)),3) AS 入库单编号
FROM (SELECT max((right(药品入库.入库单编号,3)))+1 as ID
FROM 药品入库 where 入库日期=':入库日期') AS A
说明:触发执行点为:“记录新增后”; 替换字段为相应单号,不建议“替换后自动保存”
我们推荐第一种按照电脑日期自动生成编码的方式。