各位大哥 查询条件为‘2005-7-7 12:55:44’应该如何写?我写了 select * from aa where submit_date=‘2005-7-7 12:55:44’但查不到记录

解决方案 »

  1.   

    select * from aa where submit_date=convert(datetime,'2005-7-7 12:55:44')
      

  2.   

    1确定数据库中有此时间记录
    2select * from aa where submit_date=convert(datetime,'2005-7-7 12:55:44')
    看看对吗,
      

  3.   

    select * from aa where convert(datetime,submit_date,120)=convert(datetime,'2005-7-7 12:55:44',120)
      

  4.   

    如果你查询时有没有报错啊?
    请检查一下全半角打错没
    --如果submint_date 为日期型
    Declare @aa Table(id int,submint_date Datetime) 
      Insert @aa Select 1,'2005-7-7 12:55:44'
       Union All Select 2,'2005-7-7 12:58:44'
    Select * From @aa
    select * from @aa where submint_date='2005-7-7 12:55:44'(所影响的行数为 2 行)id          submint_date                                           
    ----------- --------------------------
    1           2005-07-07 12:55:44.000
    2           2005-07-07 12:58:44.000(所影响的行数为 2 行)id          submint_date                                           
    ----------- ---------------------------
    1           2005-07-07 12:55:44.000(所影响的行数为 1 行)
      

  5.   

    我觉得问题不是出在convert(datetime,'2005-7-7 12:55:44')
    要是submit_date 即使是字符型的话,
    按楼主的那种查法同样可以看出结果来的,并不需要转换成DateTime
      

  6.   

    这么结果够怪的
    没报错 说明sql没问题.但就是没结果.
      

  7.   

    应该是LZ的数据表中数据的问题
    LZ给出的只是到秒级数据而且事实上数据库里存的是毫秒级数据,应该是数据库里数据毫秒不是0所以才查不到吧
      

  8.   

    应该是LZ的数据表中数据的问题
    LZ给出的只是到秒级数据而且事实上数据库里存的是毫秒级数据,应该是数据库里数据毫秒不是0所以才查不到吧
    ---------------
    应该是这个原因!
      

  9.   

    select * from aa where cast(submit_date as varchar(20)) =‘2005-7-7 12:55:44’這樣呢
      

  10.   

    or 
    select * from aa where patindex('%2005-7-7 12:55:44’%',submit_date)>0
    這樣試試看,應該可以的
      

  11.   

    打錯了select * from aa where patindex('%2005-7-7 12:55:44%',submit_date)>0
      

  12.   

    datetime从 1753 年 1 月 1 日到 9999 年 12 月 31 日的日期和时间数据,精确度为百分之三秒(等于 3.33 毫秒或 0.00333 秒)。你插入的时候应该使用 getdate() 吧,这样估计是查不到的,因为里面存放的时间精确到了 百分之三 秒。select * from aa where submit_date between '2005-7-7 12:55:43' and '2005-7-7 12:55:45'试试看。
      

  13.   

    Declare @aa Table(id int,submint_date Datetime) 
    Insert @aa Select 1,'2005-7-7 12:55:44.11'
    Union All Select 2,'2005-7-7 12:58:44'select * from @aa where datediff(s,submint_date,'2005-07-07 12:55:44')=0
    /*结果
    1     2005-07-07 12:55:44.110
    */
    用这个吧.只比到秒.在你提交的时候系统会记录到毫秒级
    而你的比较参数只到秒.
    这样就会出现查不出来的情况.
      

  14.   

    试试这个.
    select * from aa where submit_date between '2005-07-07 12:55:44' and '2005-07-07 12:55:45'