Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 转换和连接_Sql Server 2008_Date_String Concatenation - Fatal编程技术网

Sql server 2008 转换和连接

Sql server 2008 转换和连接,sql-server-2008,date,string-concatenation,Sql Server 2008,Date,String Concatenation,我的输入是整数形式的月份和年份 月-年 2011年8月 2012年9月 2012年10月 我希望输出作为月份和年份连接为月份名称和年份 周一 2011年8月 2012年9月 2012年10月 请在这个问题上帮助我。试试这个: 使用DateName函数查找月份名称,但该函数需要一个日期值作为输入,因此在内部查询中将月份号转换为日期 declare @month int=3 declare @year int=2012 Select DateName( month , DateAdd( m

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

  • 月-年
  • 2011年8月
  • 2012年9月
  • 2012年10月
我希望输出作为月份和年份连接为月份名称和年份

  • 周一
  • 2011年8月
  • 2012年9月
  • 2012年10月
请在这个问题上帮助我。

试试这个:

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

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

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

March 2012

下面是另一个解决方案:

declare @month int
declare @year int

select @month = 3
select @year = 2012

select datename(month , dateadd(mm, @month, '20120101')) + ' ' + cast(@year as char(4))