送分,菜鸟问题!

highscore2 2004-04-13 03:22:36
如何把字符串 "Jan 2004" 转为 "January 2004" 即把月的简称转成全称?
...全文
35 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbsql 2004-04-13
  • 打赏
  • 举报
回复
不用那么麻烦吧,试试:
declare @s varchar(20)
set @s='Jan 2004'
SET LANGUAGE us_english
print datename(mm,@s)
netcoder 2004-04-13
  • 打赏
  • 举报
回复
我写了个函数,是用笨方法的,我想肯定有好的解决办法


create function getFullMonth(@month as varchar(20))

RETURNS varchar(20)
as

begin
declare @temp varchar(6)
set @temp=substring(@month,1,3)

set @month= case
when substring(@month,1,3)=substring('January',1,3) then replace(@month,@temp,'January')
when substring(@month,1,3)=substring('February',1,3) then replace(@month,@temp,'February')
when substring(@month,1,3)=substring('March',1,3) then replace(@month,@temp,'March')
when substring(@month,1,3)=substring('April',1,3) then replace(@month,@temp,'April')
when substring(@month,1,3)=substring('May',1,3) then replace(@month,@temp,'May')
when substring(@month,1,3)=substring('June',1,3) then replace(@month,@temp,'June')
when substring(@month,1,3)=substring('July',1,3) then replace(@month,@temp,'July')
when substring(@month,1,3)=substring('August',1,3) then replace(@month,@temp,'August')
when substring(@month,1,3)=substring('September',1,3) then replace(@month,@temp,'September')
when substring(@month,1,3)=substring('October',1,3) then replace(@month,@temp,'October')
when substring(@month,1,3)=substring('November)',1,3) then replace(@month,@temp,'November')
when substring(@month,1,3)=substring('December',1,3) then replace(@month,@temp,'December')
end

return @month
end

--调用 select dbo.getFullMonth('jan 2004')

netcoder 2004-04-13
  • 打赏
  • 举报
回复
难就难在
参数 @Month varchar(23),是字符类型,而又不是sqlsrver支持的格式
internetcsdn 2004-04-13
  • 打赏
  • 举报
回复
下例将默认语言设置为 us_english。

SET LANGUAGE us_english
GO

internetcsdn 2004-04-13
  • 打赏
  • 举报
回复
up
pbsql 2004-04-13
  • 打赏
  • 举报
回复
SET LANGUAGE us_english
select datename(mm,'2004-1-1')
highscore2 2004-04-13
  • 打赏
  • 举报
回复
不是吧,这个问题很复杂吗?
参数 @Month varchar(23) --格式为 'mmm yyyy' 如:'jan 2004'
我希望能转成 显示全月名而不是月的简称,如 'January 2004'

zheninchangjiang(我爱燕子)的方法太死板了,有没有更好的方法
zheninchangjiang 2004-04-13
  • 打赏
  • 举报
回复
replace('Jan 2004','Jan','January') --呵呵,简单的不会
highscore2 2004-04-13
  • 打赏
  • 举报
回复
在线等待中...

34,873

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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