比如我要查一张表里ActiveDate为2009年12月的所有数据除了select * from 表1 where ActiveDate between '2009-12-1' and '2009-12-31';
select * from 表1 where ActiveDate >='2009-12-1' and <='2009-12-31';
select * from 表1 where year(ActiveDate)='2009' and month(ActiveDate)='12'之外
还有没有其它用函数可以解决的方法?

解决方案 »

  1.   

    select *
    from tb1
    where convert(char(7),activedate,120) = '2009-12'
      

  2.   

    select * from 表1 where ActiveDate between '2009-12-1' and '2009-12-31 23:59:59'
      

  3.   

    select
      *
    from
      tb
    where
      convert(varchar(10),ActiveDate,7)='2009-12'
      

  4.   

    where convert(varchar(7),getdate(),120)='2010-12'
      

  5.   

    select * from 表1 where ActiveDate between '2009-12-1' and '2009-12-31'; 
    select * from 表1 where ActiveDate >='2009-12-1' and <='2009-12-31'; 这两句就挺好的,可以用到SARG,比函数好
      

  6.   

    select * from 表1 where datepart(year,ActiveDate)='2009' and datepart(month,ActiveDate)='12'
      

  7.   

    Thank all you a lot!