插入数据 存储过程生成帐单号

CREATE PROCEDURE InsertUserAccount
    @Phone        NVARCHAR(15),
    @Point          int,
    @Status            NVARCHAR(50),
    @Step1Time     DATETIME  ,
    @PayBy       NVARCHAR(100),
    @ID           INT = 0 OUTPUT
AS
    SET NOCOUNT ON

-----------------------------------------生成流水号作为单据号--------------------------------
declare @ordid nvarchar(100)
declare @ord nvarchar(100)
declare @time nvarchar(100)

select @ord=isnull(max(right(orderNO,6)),'000000') from UserAccount  where left(orderNO,8)=CONVERT(varchar,getdate(),112)
set @ord=cast((cast(@ord as bigint)+1) as varchar)
if(len(@ord)<6)
begin
 SET @ord = '000000' + @ord
 SET @ord = substring(@ord, len(@ord) - 5, 6)
end

set @time=CONVERT(varchar,getdate(),112)

set @ordid=@time+@ord

---------------------------------------------------------------------------------
 INSERT [UserAccount] (orderNO,  phone, point,status, Step1Time, PayBy)SELECT @ordid, @Phone, @Point,
 @Status,@Step1Time,@PayBy

 select @ordid

------------------------------------------------
GO

posted @ 2008-07-13 10:21  网络金领  阅读(611)  评论(0编辑  收藏  举报