明明数据库中有pb_date=‘2009-4-26 11:29:47’这条记录为什么进行下面查询时结果却为空呢?select * from notic where pb_date='2009-4-26 11:29:47'请指教!

解决方案 »

  1.   

    pb_date字段的类型是什么? varchar还是datetime?
    pb_date=‘2009-4-26 11:29:47’字符怎么看起来是全角的?
      

  2.   

    是datetime型 我运行时用的是半角pb_date='2009-4-26 11:29:47'啊仍为空
      

  3.   

    select * from notic where convert(varchar(18),pb_date)='2009-4-26 11:29:47'
    试试这吧,应该可以的 
      

  4.   

    秒数一样好,毫秒数还可能不一样啊,两个时间还是不一定相等比较两个时间是不是同一天
    select * from notic where datediff(d,pb_date,'2009-4-26 11:29:47')=0
    比较两个时间是不是同一秒
    select * from notic where datediff(s,pb_date,'2009-4-26 11:29:47')=0
      

  5.   

    select * from notic where datediff(s,pb_date,'2009-4-26 11:29:47')=0 
    这样查询就可以得到你要的结果了,其中s代表比较两个时间相差多少秒
      

  6.   

    select * from notic where CONVERT(varchar, pb_date, 120 )='2009-4-26 11:29:47'
      

  7.   

    select * from notic where cast(varchar(10),pb_date,120)='2009-4-26'试试
      

  8.   

    我知道因为我在插入时pb_date=getdate()sql默认是精确到毫秒的 但是我查询时只是到秒 所以没找到匹配项  大家说应该如何按照pb_date字段写sql查询语句呢