1、数据库有两个字段:【年】、【月】,都是 int 类型
2、我想得到: >= 2010年5月,并且 <= 2011年12月

解决方案 »

  1.   

    这个可以直接用条件过滤啊
    大于等于2010年5月 条件就是  ((年份=2010 and 月份>=5) or 年份>2010) and (相同逻辑 <=2011年12月)
      

  2.   

    将年月两个字段相加,SELECT [year]+[month] FROM TableName  得到如201104 这样的,后用CONVERT 函数转换一下。希望对你有帮助
      

  3.   

    --虚拟临时表
    with tb1 as
    (
    select 1 as id ,2009 as v_year,5 as v_month union all
    select 2,2010,12 union all
    select 3,2011,2 union all
    select 4,2010,5 union 
    select 5,2010,7 
    )
    select * from tb1
    where v_year>=year('2010-05-01') and v_month>=MONTH('2010-05-01') 
    and 
      v_year<=year('2011-12-01') and v_month<=MONTH('2011-12-01') 
    /*
    id          v_year      v_month
    ----------- ----------- -----------
    2           2010        12
    4           2010        5
    5           2010        7(3 row(s) affected
    */
      

  4.   

    [code=SQL]
    insert into # tab1
    select  tab2.*  from tab2  where  year>='2010' and  month>'05'select  *  from   tab1  where  year<='2011' and  month<='12'
    [code]
      

  5.   

    http://topic.csdn.net/u/20120613/01/ac7d8d4f-1aa6-4bf5-aeda-d31eccf33fcb.html?88763可以看看我这个帖子有没有作用
    http://blog.csdn.net/dba_huangzj/article/details/7657979这篇是完整版