通过指定日期列来选择行

时间:2012-06-04 23:50:51

标签: sql sql-server date select sql-server-ce

我的表中有这条记录

Name   UserName     Password     DateAdded
skype  someusername somepassword 05/06/2012 01:18:50

我正在尝试执行此语句,但它总是失败。

一些尝试:(都失败了)

Select * from Passwords where DateAdded = '05/06/2012 01:18:50'
Select * from Passwords where DateAdded = #05/06/2012 01:18:50#
Select * from Passwords where DateAdded = '06/05/2012 01:18:50'
Select * from Passwords where DateAdded = '2012/06/05 01:18:50'
Select * from Passwords where DateAdded = '2012/05/06 01:18:50'
Select * from Passwords where DateAdded like '2012/06/05 01:18:50'

我的数据库中的DateAdded列的类型为datetime,而不是nvchar

我是SQL的新手,这个查询出了什么问题?

1 个答案:

答案 0 :(得分:0)

你可能会存储小数秒吗?试试这个:

SELECT * FROM Passwords
    WHERE DateAdded BETWEEN '2012-05-06 01:18:50' AND '2012-05-06 01:18:51';

(我更喜欢datetime文字的格式,因为它是明确的,但是你的格式也应该有效.Tsql将采用almost anything you throw at it