日期转换

水中影子 2010-06-26 08:13:56
字符串

现有一表 tab

date
------------
JAN-06
FEB-06
MAY-06
DEC-06
...

如何转换成(不想用case left(date,3)when ...)
date
-----------
2006-01-01
2006-02-01
2006-05-01
。。。
...全文
75 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
水中影子 2010-06-27
  • 打赏
  • 举报
回复
看来没有更好的办法了

结贴
obuntu 2010-06-26
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 pt1314917 的回复:]

只能这样了
[/Quote]

up
chunchun0039 2010-06-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 bobo12082119 的回复:]

学习了,好像解决了!
[/Quote]+1
304的的哥 2010-06-26
  • 打赏
  • 举报
回复
学习了,好像解决了!
jaydom 2010-06-26
  • 打赏
  • 举报
回复

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
jaydom 2010-06-26
  • 打赏
  • 举报
回复
楼主可以自己写一个函数来做这个
pt1314917 2010-06-26
  • 打赏
  • 举报
回复
只能这样了

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧