SQL生成流水帐号的函数

--创建函数
--
 =============================================
--
 Author:        ajayumi
--
 Create date: 2008-05-12
--
 Description:    生成流水帐号
--
 =============================================
CREATE FUNCTION GetID()
RETURNS Varchar(12)
AS
BEGIN
    
-- Declare the return variable here
    DECLARE @Temp varchar(12)

    
-- Add the T-SQL statements to compute the return value here
    select @Temp = convert(varchar(8),getdate(),112)+ Right(10000+Convert(int,Right(ISNULL(Max([id]),0),4))+1,4
    
From newstable 
    
Where Left(ID,8= convert(varchar(8),getdate(),112)
    
    
-- Return the result of the function
    RETURN @Temp
END
GO

这里需要修改一下表名(newstable)和相应的字段名(ID),有时间再将这个函数完善吧!
posted @ 2008-05-30 02:45  ajayumi  阅读(241)  评论(0)    收藏  举报