呵呵。和我以前涉及到的编号差不多的模式。我是过了1天编号就好重1开始,例子<br>CREATE PROCEDURE WLS_Sale <br>@machinid varchar(2), <br>@salenumid int,<br>@salename varchar(30), <br>@saleprice money, <br>@salepreprice money, <br>@saleFlag varchar(20),<br>@Ticket_Count int,<br>@repeatprn int,<br>@disableticket bit,<br>@operid varchar(3), <br>@opername varchar(20),<br>@saledatetime datetime output,<br>@saleid varchar(6) output <br> AS<br>declare<br>@i int,@diffday int, /*@i 存记录数,@diffday存间隔人数*/<br>@datelast datetime, /*库中最后的日期 set @i=cast(@maxid as int)*/<br>@maxid varchar(6),@OldTicket_Count int /*当天最后记录的ID*/<br><br>select @datelast=max(Sale_Datetime) from day_SaleRecords /*取库中最后的日期*/<br>set @diffday=datediff(Day,@datelast,@saledatetime)<br><br>select @i=count(*) from day_SaleRecords where datediff(Day,@datelast,Sale_Datetime)=0/*是否存在记录*/<br><br>if (@i=0) or (@diffday>0) <br> begin<br> set @saleid='000001' <br> end<br> else<br> begin /*计算当天每笔零售票号*/<br> select @maxid=max(Sale_ID) from day_SaleRecords where datediff(Day,@datelast,Sale_Datetime)=0 /*取当天最后记录的ID*/<br> select @OldTicket_Count=Ticket_Count from day_SaleRecords where sale_id=(select max(sale_id) from day_salerecords where datediff(Day,@datelast,Sale_Datetime)=0) and datediff(Day,@datelast,Sale_Datetime)=0<br> set @saleid=right('000000'+ltrim(str(cast(@maxid as int)+@OldTicket_Count,6,0)),6) /*生成新ID*/<br> end<br>set @saledatetime=getdate() /*当前日期时间*/<br> /*日期时间,机器ID,套票号,原价,套票名称,优惠价,重打次,是否退票,操作员ID,操作员名)*/<br>insert LS_SaleRecords values(@saledatetime,@machinid,@saleid,@salenumid,@salename,@saleprice,@salepreprice,@saleFlag,@Ticket_Count,@repeatprn,@disableticket,@operid ,@opername)<br>insert Day_SaleRecords values(@saledatetime,@machinid,@saleid,@salenumid,@salename,@saleprice,@salepreprice,@saleFlag,@Ticket_Count,@repeatprn,@disableticket,@operid ,@opername)<br>----------------------------------------<br>GO