sql-server-2008 - 转换和连接

标签 sql-server-2008 date string-concatenation

我的输入是整数形式的月份和年份。

  • 年月
  • 2011 年 8 月
  • 2012 年 9 月
  • 2012 年 10 月

我希望将月份和年份的输出连接为月份名称和年份。

  • mon_yr
  • 2011 年 8 月
  • 2012 年 9 月
  • 2012 年 10 月

请帮我解决这个问题。

最佳答案

试试这个:

使用 DateName 函数查找 month_name,但该函数需要一个日期值作为输入,因此在内部查询中将月份数字转换为日期。

declare @month int=3
declare @year int=2012

Select DateName( month , DateAdd( month , @month , 0 ) - 1 )
                                           +' '+cast( @year as char(4))

结果:

March 2012

关于sql-server-2008 - 转换和连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12174420/

相关文章:

python - dateutil.parser 的奇怪行为

python - 在 Python Pandas 中创建新的 QuarterEnd 列

c# - 是什么导致了字符串连接时间的激增?

sql-server-2008 - SQL Server 2008 : Where is the change tracking table stored?

sql - "Incorrect syntax near ' OFFSET '"修改sql comm 2012到2008

SQL Server 函数根据参数返回不同的选择语句

objective-c - ALAssetPropertyDate 返回 "wrong"日期

sql-server-2008 - 折叠/展开代码块

字符串常量的 C# 编译时连接

javascript - 如何声明一个没有值的变量?