sql server 連續月

select * from
  (SELECT top 12
convert(varchar(7),dateadd(MONTH,
-(b3.i + b2.i + b1.i + b0.i),
dateadd(month,2,GETDATE())),21) as i
FROM
(  SELECT 0 i UNION ALL SELECT 1) b0
CROSS JOIN (SELECT 0 i UNION ALL SELECT 2) b1
    CROSS JOIN (SELECT 0 i UNION ALL SELECT 4) b2
    CROSS JOIN (SELECT 0 i UNION ALL SELECT 8) b3
order by b0.i + b1.i+b2.i+b3.i ) b order by b.idate

相關文章
相關標籤/搜索