sqlite 自动编号问题
时间:2020-08-15 访问量:1165
平时是根据strftime('%Y-%m-%d','now')自动生成单号,但是有的客户凌晨至8点之前录入的单子,单号还是根据昨天单号累加的。
后经过测试:如果用下列语句,本地下午的时间,编号不对了。
改成下面的语句:(截止发搞前目前没发现问题)
新增后:
SELECT (case when Ay.号 is null then CAST(strftime('%Y',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(4))||
CAST(strftime('%m',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))||
CAST(strftime('%d',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))||'0001'
else CAST(strftime('%Y',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(4))||
CAST(strftime('%m',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))||
CAST(strftime('%d',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))||substr(10000+Ay.号,2,4) end) as 入库单号
from (select max(substr(登记编号,9,4))+1 as 号
from 业务资料 where substr(登记编号,1,8)=CAST(strftime('%Y',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(4))||
CAST(strftime('%m',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))||
CAST(strftime('%d',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))) as Ay
保存前:
SELECT (case when ':接尸单号'=' Null' or ':接尸单号'=''
then "J"||
(case when a.id is null then CAST(strftime('%Y',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(4))||
CAST(strftime('%m',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))||
CAST(strftime('%d',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))||'001' else A.ID end)
else ':接尸单号' end) as 接尸单号
from (select max(substr(接尸单号,2,11))+1 as ID from 接尸信息
where 类型=':类型' and substr(接尸单号,2,8)=CAST(strftime('%Y',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(4))||
CAST(strftime('%m',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2))||
CAST(strftime('%d',datetime(CURRENT_TIMESTAMP,'localtime')) AS VARCHAR(2)) ) as A
-------后客户反应,傍晚的单子还是不对,建议用下面的
:登记日期 必须 默认当天,且不能修改
SELECT (case when Ay.ID is null then "S" || replace(':登记日期','-','')||'001' else "S" || replace(':登记日期','-','')||substr(1000+Ay.ID,2,3) end) as 入库单号 from (select max(substr(销售单号,10,3))+1 as ID from 销售单 where substr(销售单号,1,9)="S" || replace(':登记日期','-','')) as Ay