Fork me on GitHub

曾今的代码系列——获取当天最大流水号存储过程

获取当天最大流水号存储过程

alter procedure usp_getSelfSeqNo
(
    @seqName nvarchar(32),
    @result int output
)
as
begin
    --判断当天是否存在该名字的流水号
    begin tran
    declare @todayCount int
    select @todayCount=COUNT(*) from T_DailySeqNo 
    where SeqName=@seqName and DATEDIFF(DAY,SeqDate,GETDATE())=0
    if @todayCount<=0--不存在,则插入相应的流水号
    begin
        insert into T_DailySeqNo (SeqName,SeqDate,CurValue)
        values(@seqName,convert(varchar(10),GETDATE(),20),0)--默认初始值为0
    end
    else--否则,更新+1
    begin
        update T_DailySeqNo set CurValue=CurValue+1
        where SeqName=@seqName and DATEDIFF(DAY,SeqDate,GETDATE())=0
    end
    select @result=curvalue from T_DailySeqNo --获取当天的流水号
    where SeqName=@seqName and DATEDIFF(DAY,SeqDate,GETDATE())=0
    commit
end

d

posted @ 2012-09-07 02:18  木宛城主  阅读(743)  评论(0编辑  收藏  举报
multifunction lasers
访问人数