select * from sheet where convert(varchar(10),sh_time,112) between rq1 and rq2

解决方案 »

  1.   

    还是不行啊
    我的sql 语句是
    string myCommand = "select distinct * from archiveSheet where (convert(varchar(10),archiveSheet.sh_time,112) between rq1 and rq2) and archiveSheet.sh_type='0C'";  
    调试出来说,没有这个dataset啊!,rq1,rq2没问题的
      

  2.   

    select distinct * from archiveSheet where 
    (sh_time>=cast(rq1 as datetime and cast(rq2 as datetime) and archiveSheet.sh_type='0C'
      

  3.   

    我现在发现我的sh_time 格式为如果月份小的话是2002-2-10,那转换为convert(varchar(10),archiveSheet.sh_time,112),不是还不能判断啊,有其他的方法提供吗?反正是查询两个日期间的所有记录,谢谢!
      

  4.   

    select distinct * from archiveSheet where 
    sh_time>=cast(rq1 as datetime) and sh_time<=cast(rq2 as datetime) and archiveSheet.sh_type='0C'
      

  5.   

    不可能吧?
    试试这个,select convert(varchar(10),getdate(),112)
    112--就是将'2002-01-01 000:00:00' 转换成20020101的
      

  6.   

    rq1和rq2是什么类型??是'2002-2-2'的字符类型吗?是的话:
    select distinct * from archiveSheet where 
    sh_time>=@rq1 and sh_time<=@rq2 and archiveSheet.sh_type='0C'
      

  7.   

    select * from sheet where convert(varchar(10),convert(datetime ,sh_time),112) between rq1 and rq2
    这样2002-1-3类型的日期也不怕了
      

  8.   

    用你的语句就是:select distinct * from archiveSheet where (convert(varchar(10),convert(datetime ,archiveSheet.sh_time),112) between rq1 and rq2) and archiveSheet.sh_type='0C'"