select  *  from  w_content  where  EmpName  =  'wlz'  and  datediff(day,SubDate,'2003-7-18')=0原理:
select datediff(day,'2001-1-1','2002-1-1') 天
select datediff(month'2001-1-1','2002-1-1') 月
select datediff(year,'2001-1-1','2002-1-1') 年
---------------------------------------------------------------------------------
select  *  from  w_content  where  EmpName  =  'wlz'  and  CONVERT(varchar(10),SubDate,120)='2003-07-18'原理:
select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
select convert(char(8),getdate(),112) ----20020101
select convert(char(8),getdate(),108)  ---06:05:05

解决方案 »

  1.   

    select * from w_content where EmpName = 'wlz' 
       and Replace(Convert(varChar(10),SubDate,20),'-0','')='2003-7-18'
      

  2.   

    因为subdate为datetime类型,你用select * from w_content显示subdate时后有时间,也就是你这样写:select * from w_content where EmpName = 'wlz' and convert(varchar,SubDate,102) ='2003-7-18',只显示日期不显示时间!·
      

  3.   

    select  *  from  w_content  where  EmpName  =  'wlz'  and  datediff(day,SubDate,'2003-7-18')=0or
    select  *  from  w_content  where  EmpName  =  'wlz'  and  SubDate between
    '2003-7-18' and '2003-7-19'
      

  4.   

    SubDate >'2003-7-18 00:00:00' and SubDate <'2003-7-18 23:59:59'
      

  5.   

    select * from w_content where EmpName = 'wlz' 
        and convert(varhcar(10),SubDate,120) ='2003-7-18'
      

  6.   

    select * from w_content where EmpName = 'wlz' 
        and convert(varhcar(10),SubDate,120) ='2003-07-18'
      

  7.   

    问题出在时间上,因为日期型字段是包含时间的.
    你有下面的方法试试:select * from w_content where EmpName = 'wlz' and convert(varvhar(10),SubDate,120) ='2003-07-18'
      

  8.   

    如果日期是‘2003-08-18 00:00:00’的方式, 那么,使用
    select  *  from  w_content  where  EmpName  =  'wlz'  and  datediff(day,SubDate,'2003-7-18')=0
    or
    select  *  from  w_content  where  EmpName  =  'wlz'  and  SubDate between
    '2003-7-18' and '2003-7-19'
    如果日期是字符型,
    select  *  from  w_content  where  rtrim(EmpName)  =  'wlz'  and rtrim(SubDate) ='2003-7-18'
      

  9.   

    where convert(varhcar(10),SubDate,120) ='2003-07-18'如果你用subdate='2003-07-18' 那么系统默认是取这样的时间 2003-07-18 00:00:00.000
    所以如果你有的时间是2003-07-18 10:00:00.000的记录就无法取出了
      

  10.   

    where convert(varhcar(10),SubDate,120) ='2003-07-18'如果你用subdate='2003-07-18' 那么系统默认是取这样的时间 2003-07-18 00:00:00.000
    所以如果你有的时间是2003-07-18 10:00:00.000的记录就无法取出了
      

  11.   

    where convert(varhcar(10),SubDate,120) ='2003-07-18'如果你用subdate='2003-07-18' 那么系统默认是取这样的时间 2003-07-18 00:00:00.000
    所以如果你有的时间是2003-07-18 10:00:00.000的记录就无法取出了