Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

sql - 在SQL中将月份编号转换为月份名称功能(Convert Month Number to Month Name Function in SQL)

I have months stored in SQL Server as 1,2,3,4,...12.

(我在SQL Server中以1,2,3,4,... 12的形式存储了几个月。)

I would like to display them as January,February etc. Is there a function in SQL Server like MonthName(1) = January?

(我想将它们显示为一月,二月等。SQLServer中是否有像MonthName(1)= January这样的函数?)

I am trying to avoid a CASE statement, if possible.

(如果可能,我试图避免使用CASE语句。)

  ask by Saif Khan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think this is the best way to get the month name when you have the month number

(我认为这是得到月份名称时,你有个数字的最佳方式)

Select DateName( month , DateAdd( month , @MonthNumber , 0 ) - 1 )

Or

(要么)

Select DateName( month , DateAdd( month , @MonthNumber , -1 ) )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...