日期:2014-05-17 浏览次数:20794 次
create function dbo.get_num(@v varchar(20))
returns varchar(20)
as
begin
return case when right(@v,3)='120'
then CONVERT(VARCHAR(10),DATEADD(dd,1,CONVERT(varchar(100), SUBSTRING(@v,1,PATINDEX('%-%',@v)-1), 112)),112)+'-001'
else LEFT(@v,8)+'-'+right('000'+cast(right(@v,3)+1 as varchar),3)
end
end
go
select dbo.get_num('20140131-120')
/*
--------------------
20140201-001
*/
create function dbo.get_num(@str1 char(12))
returns char(12)
as
begin
DECLARE @str2 CHAR(8),@i int
SELECT @str2=LEFT(@str1,8),@i=RIGHT(@str1,3)+1
return CONVERT(CHAR(8),CAST(@str2 AS datetime)+@i/120,112)+'-'+RIGHT('00'+RTRIM(@i%120),3)
end
go
select dbo.get_num('20140131-120')
create function split_str
(@s varchar(12))
returns varchar(12)
as
begin
declare @temp int
declare @date datetime
declare @re varchar(20)
set @date=substring&n