/* Author:yucl
CreateDate:2015-09-28
FunctionName:FuncTaskNO
Remark: Description:获取任务编号
Version:V1.0 */
ALTER FUNCTION FuncTaskNO
(@TaskNO varchar(30))
returns varchar(30) BEGIN
DECLARE @TaskNewNo varchar(30)
DECLARE @TaskMaxNo varchar(30)
--获取今天最后发布的实训任务
SELECT @TaskMaxNo=MAX(taskNO) from TrainTaskInfo
where Convert(varchar(10),CreateTime,120)=Convert(varchar(10),getdate(),120)
DECLARE @CurDate varchar(16)
SELECT @CurDate=Replace( Replace(REPLACE(CONVERT(varchar(16), GETDATE(), 120),'-',''),':',''),' ','')
--今天有发布任务
IF(len(@TaskMaxNo)<>'')
begin
select @TaskNewNo=substring(@TaskMaxNo,LEN(@TaskMaxNo)-4,4)
select @TaskNewNo=Right(CONVERT(int,@TaskNewNo)+1,4)
end
--今天没有发布任务
ElSE
BEGIN
select @TaskNewNo=Right('1',4)
END
select @TaskNewNo=@CurDate+@TaskNewNo
return @TaskNewNo
END
GO