我有几个月在SQL服务器中存储为1,2,3,4,... 12。我想将它们显示为1月,2月等。在SQL中是否有一个函数 [英] I have months stored in SQL server as 1, 2, 3, 4, ...12. I would like to display them as january, february etc. Is there a function in SQL
本文介绍了我有几个月在SQL服务器中存储为1,2,3,4,... 12。我想将它们显示为1月,2月等。在SQL中是否有一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个月在SQL Server中存储为1,2,3,4,... 12。我希望将它们显示为1月,2月等。是否有SQL函数
我尝试过:
我有几个月存储 SQL Server as 1 , 2 , 3 , 4 ,... 12 。我想将它们显示为 1月,2月等。是否在 SQL $ p中有一个函数 $ p> 解决方案
试试这个
声明 @ month int
set @ month = 11 - 11月
选择 ' 月份名称' = DateName(月,DateAdd(月, @ month , 0 ) - 1 )
参考 DATENAME(Transact-SQL) [ ^ ]
希望此查询的帮助你:
选择 DATENAME(MONTH,getdate())
选择 DATENAME(MONTH,DateAdd(月, 11 , 0 ) - 1 ) - 11月份值
选择 DATENAME(月, 250 ) - - 传递1-365天的值
I have months stored in SQL Server as 1,2,3,4,...12. I would like to display them as January,February etc. Is there a function in SQL
What I have tried:
I have months stored in SQL Server as 1,2,3,4,...12. I would like to display them as January,February etc. Is there a function in SQL
解决方案 try this
declare @month int
set @month = 11 -- November
Select 'Month Name' = DateName( month , DateAdd( month , @month , 0 ) - 1 )
refer DATENAME (Transact-SQL)[^]
hope this Query's helps you:
select DATENAME(MONTH, getdate() )
select DATENAME(MONTH, DateAdd( month , 11, 0 ) - 1 ) -- 11 as month value
select DATENAME(MONTH,250 ) --- pass values from 1-365 days
这篇关于我有几个月在SQL服务器中存储为1,2,3,4,... 12。我想将它们显示为1月,2月等。在SQL中是否有一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文