条形码的值来源一个函数[201511211707 (001-999以内的数字)]

来源:互联网 发布:淘宝店主软件 编辑:程序博客网 时间:2024/05/22 09:46
create function getgcode() returns varchar(20)asbegindeclare @time varchar(20)declare @num varchar(3)='001'declare @lastnum intset @time=CONVERT(varchar(20),GETDATE(),120)set @time=REPLACE(@time,'-','')set @time=REPLACE(@time,':','')set @time=REPLACE(@time,' ','')if exists(select gcode from tbProduct where gcode like(@time+'%'))begin set @lastnum=convert(int,substring((select top 1 gcode from tbProduct where gcode like(@time+'%')order by gcode desc),15,3))+1 if(@lastnum<10) set @num='00'+CONVERT(varchar(4),@lastnum) else if(@lastnum<100) set @num='0'+CONVERT(varchar(4),@lastnum) else if(@lastnum<1000) set @num=CONVERT(varchar(4),@lastnum) set @time=@time+@numendelsebeginset @time=@time+@numendreturn @timeend

原创粉丝点击