问题描述
我要让系统自动生成订单编号,按日期,先检查当前日期是否有运单,如果没有就是当前日期+00001,如果有就是+00002依次往后。
解决方案
解决方案二:
根据日期取当前日期的max(编号),如果没有从1开始编号,如果有加1,最后转换为你的编号格式
解决方案三:
可以具体的给点代码?谢谢啊
解决方案四:
ifexists(select1fromsysobjectswhereID=object_ID('sp_GetID')andtype='p')dropprocsp_GetIDGoCREATEproceduresp_GetID@tablenamevarchar(30),--表名@strPreFixvarchar(30),--前缀@strDatechar(1),--是否需要日期0不需要,1需要@intLensmallint,--流水号长度@IDvarchar(40)output--返回IDASbegindeclare@keyIDbigintdeclare@strCurdatechar(8)declare@strPostPrefixvarchar(30)declare@error_insertint,@error_deleteintselect@strCurdate=convert(char(8),getdate(),12)select@error_insert=0select@keyID=0if@strDate='1'Select@keyID=isnull(keyID,0)FromTbas_KeyIDwhereTableName=@tablenameandcurdate=@strCurdateelseSelect@keyID=isnull(keyID,0)FromTbas_KeyIDwhereTableName=@tablenameBEGINTRANdeleteTbas_KeyIDwheretablename=@tablenameselect@error_delete=@@errorIf(@keyID=0)select@keyID=1elseselect@keyID=@keyID+1Select@strPostPrefix=REPLICATE('0',@intlen-len(ltrim(str(@keyID))))+ltrim(str(@keyID))select@strPostPrefix=ltrim(@strPostPrefix)If@strDate='1'begininsertintoTbas_KeyID(keyID,tablename,curdate)values(@keyID,@tablename,@strCurdate)select@ID=rtrim(@strprefix+@strCurdate)+@strPostPrefixendelsebegininsertintoTbas_KeyID(keyID,tablename)values(@keyID,@tablename)select@ID=@strprefix+@strPostPrefixendselect@error_insert=@@errorif@error_insert<>0or@error_delete<>0beginROLLBACKTRANselect@ID=''endelseCOMMITTRANreturnend
解决方案五:
哦,先谢谢,我弄哈看看