22,209
社区成员
发帖
与我相关
我的任务
分享
use PracticeDB
go
if OBJECT_ID('tb') is not null
drop table tb
go
create table tb(date varchar(10))
insert into tb
select 'JAN-06' union all
select 'FEB-06' union all
select 'MAY-06' union all
select 'DEC-06'
select * from tb
if OBJECT_ID('fc_test') is not null
drop function fc_test
go
create function fc_test
(
@date varchar(10)
)returns
@temp table(date date)
as
begin
insert into @temp
select (case left(@date,3) when 'Jan' then '01'
when 'Feb' then '02'
when 'Mar' then '03'
when 'Apr' then '04'
when 'May' then '05'
when 'Jun' then '06'
when 'Jul' then '07'
when 'Aug' then '08'
when 'Sep' then '09'
when 'Oct' then '10'
when 'Nov' then '11'
when 'Dec' then '12'
else null end)+'-01'+'-20'+right(@date,len(@date)-4)
return
end
select (select *
from fc_test(date)) as [date]
from tb
date
2006-01-01
2006-02-01
2006-05-01
2006-12-01