select出指定日期的数据怎么取?(20分)

O

oldnew

Unregistered / Unconfirmed
GUEST, unregistred user!
数据库中已经有一字段为DateTime类型!(包含了时间)

现在比如我要取日期为'2002-10-01'的数据,不管时间是多少!
这个select语句应该怎么写?
 
select Datepart(yyyy, @datetime) + '-' + Datepart(mm, @datetime) + '-' Datepart(dd, @datetime)
 
这个不行噢!'2002-10-01'好象还要转换一下!不会有这么复杂吧???
SELECT *
FROM hpd
WHERE (DATEPART(yyyy, rq) + '-' + DATEPART(mm, rq) + '-' + DATEPART(dd, rq) = '2002-10-01')
ORDER BY hpdh
 
试一下这样行不:
starttime:='2002-10-01'+'00:00';
endtime:='2002-10-01'+'24:00';
再用select * from where... >=starttime and <=endtime....
 
这个方法不错噢!
不过好象用“24:00:00”会出错噢!我用“23:59:59”就不会出错
 
有24:00:00这个时间么?
 
试一下这样行不:
starttime:='2002-10-01';
endtime:='2002-10-02'
再用select * from where... >=starttime and <endtime
一般一个月,如果用范围也是这样处理,这样不管有没有时间,都不会错的。
 
Select * from table1 where year(rq)*10000+month(rq)*100+day(rq)=20021001
 
就看你用什麼數據庫了。
SQLSERVER的話,用CONVERT(VARCHAR(10),DATEFIELD,120)取得日期字符作為條件就行。
 
where year(date)=2002 and month(date)=10 and day(date)=1
 
用format可也!!
 
你没有说是什么数据库啊,这叫人怎么教你?
 
SQL忧化第一步,函数尽量不要用在包含索引的字段上:
SELECT * FROM table
WHERE (fld >= CONVERT(DateTime, '2003-1-14')) AND (fld < CONVERT(DateTime,
'2003-1-15'))
 
SELECT * FROM table
WHERE between ''2003-1-14'' AND ''2003-1-15''
 
select * from table where formatdatetime('yyyy-mm-dd',rq)='2002-10-01'
 
SELECT * FROM table
WHERE 时间字段的名称 = '2002-10-01'

 
select * from table where
substring(convert(char(10),DateTimeField,126),1,10)='2002-10-01'
 
select * from tablename where columnName=convert(datetime,'2002-10-01')
 
用时间函数转换一下,看看可不可以
 
顶部