declare @CurDate datetime, @SerialNumber varchar(100)
set @CurDate=GETDATE();--获取当前时间
select @SerialNumber = Cast( RIGHT( year(@CurDate),4) as varchar) + --年
right('00' + cast(month(@CurDate) as varchar),2) + -- 月
right('00' + cast(day(@CurDate) as varchar),2)+
right('00' + cast(DateName(hour,@CurDate) as varchar),2)+
right('00' + cast(DateName(mi,@CurDate) as varchar),2)+
right('00' + cast(DateName(ss,@CurDate) as varchar),2)+
right('00' + cast(DateName(ms,@CurDate) as varchar),2)
set @SerialNumber = @SerialNumber+ cast(@dwUserID as varchar)
用日期+时间+用户id
举个栗子:写入时间 2020-10-07 17:23:39.667 用户id 14231 得到唯一序列号 202010071723396714231