我有一个使用microsoftsqlserverstudio的存储过程我有个月被存储为01,02,03,04等

polkgigr  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(347)

这是我的存储过程。有什么我可以添加到这个将返回月份的名称,而不是01,02,03,。。。。或者我可以用一个开关盒或者c#。。我正在使用visual studio 2017 c#asp.net mvc。

Select distinct statementMonth
from dbo.ClientStatement_Inventory
order by statementMonth asc
bq3bfh9z

bq3bfh9z1#

你可以用12个分支构建一个大的case表达式。
一个更简单的解决方案,可以像 '01' , '02' , ... 对于月名,使用字符串串联和日期函数,如:

datename(month, '2020' + statementMonth + '01') as statementMonthName

或者,如果你有一个数字而不是一个字符串:

datename(month, datefromparts(2020, statementMonth, 1)) as statementMonthName

相关问题