703
社区成员
发帖
与我相关
我的任务
分享,tab1(pdate) as (
select '23MAR16' union all
select '21JAN17'
)
这个是我的测试数据表。你自己的库里不是有tab1表么?
把这段删了,执行SET LANGUAGE 'us_english'
DECLARE @DT VARCHAR(50) = '23MAR16'
SELECT CONVERT(SMALLDATETIME,@DT)
with mon(num,str) as (
select '01','JAN' union all
select '02','FEB' union all
select '03','MAR' union all
select '04','APR' union all
select '05','MAY' union all
select '06','JUN' union all
select '07','JUL' union all
select '08','AUG' union all
select '09','SEP' union all
select '10','OCT' union all
select '11','NOV' union all
select '12','DEC'
)
,tab1(pdate) as (
select '23MAR16' union all
select '21JAN17'
)
select pdate,CAST('20'+SUBSTRING(t.pdate,6,2)+mon.num+SUBSTRING(t.pdate,1,2) as DATE) Date型
from tab1 t
join mon on SUBSTRING(t.pdate,3,3)=mon.str