日期:2014-05-17 浏览次数:20620 次
if OBJECT_ID('test')is not null drop table test go create table test( [year] int, [month] int ) go insert test select 2011,8 union all select 2011,9 union all select 2011,10 union all select 2011,11 union all select 2011,12 union all select 2012,1 union all select 2012,2 union all select 2012,3 union all select 2012,4 union all select 2012,5 union all select 2012,6 union all select 2012,7 union all select 2012,8 union all select 2012,9 go select * from test where [year]=case when month(GETDATE())<>1 then year(getdate()) else year(getdate())-1 end and [month]=(case when month(GETDATE())=1 then 12 else month(GETDATE())-1 end) /* year month ----------------- 2012 5 */