呕心沥血整理的一个自动编号解决方案
老生常谈 自动编号
1.简单粗暴 用帆软自带的uuid 永不重复
2.有特殊需求的编号 有自定义格式的
① 首推的方法 ,个人思路,可以在使用中感受
if(len(sql("GJLOrders","select max(t.Ht_code) Ht_code from Ht_manage t where t.Ht_code like 'HT"+FORMAT(TODAY(),"yyyyMMdd")+"%'",1,1))==0,"HT"+FORMAT(TODAY(),"yyyyMMdd")+"00001",
CONCATENATE(
left(sql("GJLOrders","select max(t.Ht_code) Ht_code from Ht_manage t where t.Ht_code like 'HT"+FORMAT(TODAY(),"yyyyMMdd")+"%'",1,1),10),
RIGHT(CONCATENATE("00000000000",
RIGHT(sql("GJLOrders","select max(t.Ht_code) Ht_code from Ht_manage t where t.Ht_code like 'HT"+FORMAT(TODAY(),"yyyyMMdd")+"%'",1,1),5)+1),5))
) 好吧 这里丢人了
公式改为
if(len(sql("GJLOrders","select max(t.Ht_code) Ht_code from Ht_manage t where t.Ht_code like 'HT"+FORMAT(TODAY(),"yyyyMMdd")+"%'",1,1))==0,"HT"+FORMAT(TODAY(),"yyyyMMdd")+"00001",
CONCATENATE(
left(sql("GJLOrders","select max(t.Ht_code) Ht_code from Ht_manage t where t.Ht_code like 'HT"+FORMAT(TODAY(),"yyyyMMdd")+"%'",1,1),10),
format(
RIGHT(sql("GJLOrders","select max(t.Ht_code) Ht_code from Ht_manage t where t.Ht_code like 'HT"+FORMAT(TODAY(),"yyyyMMdd")+"%'",1,1),5)+1),"00000")
)
好长的公式 实际很简单 查询到当日最大的.然后尾号加1 就酱 。
并发防重复: 设置主键 并且吧公式绑定给字段
②整理的论坛高手的其他方式
http://bbs.fanruan.com/thread-69961-1-1.html
http://bbs.fanruan.com/thread-69750-1-1.html
欢迎补充和完善 越简单越好 越叼越好