id  mydate
1   2010-12-12 15:04:15
2   2010-12-22 15:05:22
3   2010-11-18 08:24:07
4   2010-11-18 17:30:58
5   2010-11-29 08:06:41
6   2010-11-29 07:38:10
7   2010-12-14 17:41:41
8   2010-12-13 16:49:18
9   2011-01-06 11:02:34其中 mydate类型为 varchar想取出日期在 2010年12月1号到2010年12月31号的记录,谢谢大家!

解决方案 »

  1.   

    select * from tb where convert(varchar(10),mydate,120) between '2010-12-01' and '2010-12-31'
      

  2.   

    Select * from Where cast(mydate as datetime) between '2010-12-01' and '2010-12-31'
      

  3.   

    直接这样就可以
    select * from tb where mydate>='2010-12-01'  and mydate<'2010-12-32'
      

  4.   


    select * from tb where  mydate between '2010-12-1' and '2010-12-31'
    select * from tb where datepart(year,madate)=2010 and datepart(MM,madate)=12
      

  5.   

    --> 测试数据:[TB]
    if object_id('[TB]') is not null drop table [TB]
    create table [TB]([id] int,[mydate] VARCHAR(20))
    insert [TB]
    select 1,'2010-12-12 15:04:15' union all
    select 2,'2010-12-22 15:05:22' union all
    select 3,'2010-11-18 08:24:07' union all
    select 4,'2010-11-18 17:30:58' union all
    select 5,'2010-11-29 08:06:41' union all
    select 6,'2010-11-29 07:38:10' union all
    select 7,'2010-12-14 17:41:41' union all
    select 8,'2010-12-13 16:49:18' union all
    select 9,'2011-01-06 11:02:34'select * from [TB] WHERE mydate >'2010-12-01'  AND mydate <'2010-12-31'/*
    id mydate
    1 2010-12-12 15:04:15
    2 2010-12-22 15:05:22
    7 2010-12-14 17:41:41
    8 2010-12-13 16:49:18*/直接比对即可。转换也行
      

  6.   

    Select * from Where cast(mydate as datetime) between '2010-12-01' and '2010-12-31'
      

  7.   


    select * from tb where  mydate between '2010-12-1' and '2010-12-31'
    --or
    select * from tb where  datediff(day,mydate,'2010-12-1')<=0  and datediff(day,mydate,'2010-12-31')>=0
      

  8.   

    恩 这个不错 将时间转换下convert(varchar(10) 数据库中的字段,120)
      

  9.   

    between '2010-12-01' and '2010-12-31',直接赋值即可。