本帖最后由 youqing555 于 2011-05-26 10:21:39 编辑

解决方案 »

  1.   

    为什么不用datetime保存自找麻烦。
      

  2.   

    select * from 表 where birthday_Month=5 and Birthday_Day between 26 and 28
      

  3.   

    select * from t1
    where  cast('1900-'+cast(Birthday_Month as varchar(2))+'-'+cast(Birthday_Day as varchar(2)) as datetime)
            between '1900-5-26' and '1900-6-3'
      

  4.   

    这个不能转换成日期来比较,只能从两个数字来比较。
    这里的生日可能存在的是农历的生日,会出错的
    比如select cast('2011-2-29' as datetime)
    2011年农历2月29日这天,公历是2011年4月2号。但是农历2月29转换成日期格式就报错了。
      

  5.   

    --不跨年 即@开始月*100+开始日<=@结束月*100+@结束日
    select * from tb where Birthday_Month*100+Birthday_Day between @开始月*100+开始日 and @结束月*100+@结束日--跨年 即@开始月*100+开始日>@结束月*100+@结束日
    select * from tb where Birthday_Month*100+Birthday_Day >= @开始月*100+开始日 and Birthday_Month*100+Birthday_Day<=@结束月*100+@结束日
      

  6.   


    --不跨年(@开始月<=@结束月) 即@开始月*100+开始日<=@结束月*100+@结束日
    if @开始月<=@结束月 then
    select * from tb 
    where Birthday_Month*100+Birthday_Day 
    between @开始月*100+开始日 and @结束月*100+@结束日
    else
    --跨年:分成不跨年的部分和跨年的部分,
    --不跨年的部分只需大于开始日期,跨年的部分只需小于结束日期
    select * from tb 
    where Birthday_Month*100+Birthday_Day >= @开始月*100+开始日 
           or Birthday_Month*100+Birthday_Day<=@结束月*1300+@结束日
      

  7.   

    哈哈,问题解决,采用了“coleling”的方法!
    多谢!