根据日期,流水号产生单号自定义函数
自定义函数中不可以用getdate()之类的函数
CREATE FUNCTION tad_things_Newthing_NO(@date as nvarchar(20))
RETURNS varchar(20)
AS
BEGIN
declare @no varchar(20)
declare @num int
select @no = max(thing_NO) from tad_things where left(thing_NO,8)=@date
if @no is null
set @no=@date+'-'+'01'
else
begin
set @num =right(@no,2) + 1
set @no =CONVERT(varchar, @date, 112 )+'-'+right('00' + convert(nvarchar(1), @num),2)
end
--print(@no)
return(@no)
END