select count(1) from xxx where UserID=2127 and mydate=getdate()我这里的数据默认就是 getdate()生成的所以数据
都是 
2011-6-10 17:50:03
2011-6-10 17:20:06
这样的所以我这里用getdate()也把具体的时间带上去  所以导致 查询的count为0这里如何查询 当天的呢?mydate=?这个地方的条件怎么写哇?

解决方案 »

  1.   

    擦 getdate()是当前时间啊 你怎么能查出来数据?
      

  2.   

    select count(1) from xxx where UserID=2127 and mydate=convert(nvarchar(50),getdate(),23)
      

  3.   

    select * from xxx where UserID=2127 and mydate=convert(nvarchar,getdate(),23)
      

  4.   


    你这个也查不出来 我先也是这样做的  现在我改成这样就可以查询出来了 
    不知道有没简单的办法select count(1) from xx where UserID=2127 and (select convert(varchar(10),mydata,120)) = (select convert(varchar(10),getdate(),120))
      

  5.   

    select count(1) 
    from xxx 
    where UserID=2127 and mydate=convert(char(20),getdate(),120)
      

  6.   


    select count(1) from xxx where UserID=2127 and convert(varchar(10),mydate,120)=convert(varchar(10),getdate(),120)
      

  7.   

    select count(1) from xxx where UserID=2127 and 
    convert(nvarchar(50),mydate,23)=convert(nvarchar(50),getdate(),23)
      

  8.   

    [code=SQL]select count(1) from xx where UserID=2127 and  convert(varchar(10),mydata,120) = (convert(varchar(10),getdate(),120)code]
      

  9.   

    select count(1) from xxx where UserID=2127 and datediff(day,mydate,getdate())=0
      

  10.   


    select count(1) from xxx where UserID=2127 and mydate=CONVERT(varchar(100), GETDATE(), 23)
    另附:http://blog.csdn.net/yubofighting/archive/2010/10/13/5938103.aspx