我想查询以文本形式显示当前月份,然后在下列行中打印当年余下年份,直到本年度的所有月份打印。行当前月份和当年剩余月份
这有点难以解释,所以我做了下面的例子。我知道下面的代码是荒谬的,但这是我知道用我目前的技能水平来做这件事的唯一方法。理想情况下,我还想从打印一个整数转换为打印月份的字符值(因此1将是1月)。我知道我可以通过一个案件来做到这一点,但是我确信还有一种更好的方式我还没有接触到。
declare @currentmonth as int = datepart(month, getdate())
select
@currentmonth
union
select
@currentmonth +1
union
select
@currentmonth +2
union
select
@currentmonth +3
union
select
@currentmonth +4
union
select
@currentmonth +5
union
select
@currentmonth +6
union
select
@currentmonth +7
union
select
@currentmonth +8
union
select
@currentmonth +9
union
select
@currentmonth +10
union
select
@currentmonth +11
简单eleg蚂蚁,谢谢你 – Codingo 2012-01-12 08:15:31
@迈克尔很高兴这有帮助。 – 2012-01-12 08:21:10
此功能称为行构造函数。这是一个很棒的功能。然而,与常规方式相反,使用此功能完成的大量插入操作会受到性能影响。 [相关文章](http://connect.microsoft.com/SQLServer/feedback/details/508112/insert-performance-of-row-constructor-is-quiet-bad) – Animesh 2012-01-12 11:49:36