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月
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))