已知表 work
id topdate name
1 2007/12/29 上午 10:26:35 q
2 2007/12/29 上午 10:32:47 a
3 2007/12/29 上午 10:32:48 c
4 2008/1/2 上午 10:21:31 s
5 2008/1/2 上午 10:24:36 d
6 2008/1/2 上午 10:25:31 f
求在某个时间段内的值(其中这个时间段要包含 年月日时分秒)
其中topdate 类型为datetime
id topdate name
1 2007/12/29 上午 10:26:35 q
2 2007/12/29 上午 10:32:47 a
3 2007/12/29 上午 10:32:48 c
4 2008/1/2 上午 10:21:31 s
5 2008/1/2 上午 10:24:36 d
6 2008/1/2 上午 10:25:31 f
求在某个时间段内的值(其中这个时间段要包含 年月日时分秒)
其中topdate 类型为datetime
解决方案 »
- 游标有关问题
- [SQL-DMO]名称“TB_2004”在 TransArticles 集合中没有找到。
- 好奇怪的ODBC问题
- 请教:如何用“分析查询器”将*.sql的文件导到数据库中?给分30
- 问一下数据库表中类型字段为什么要用数字?
- 如何将视图中的所有数据插入至新建的表中
- visual studio 2005环境 ,日文版——>中文版
- SQL Server 2005 的 sp_helpuser问题?
- 在VC中,怎样实现将数据库的表中的一项数据(text类型)读出来?在线等待,回复马上给分!
- SQL Server里如何根据表的记录生成insert.sql文件?
- 我是小菜鸟,急需要大侠的帮忙,求求大伙了,急等用啊!谢谢啊!
- 求一SQL语句....详情请进...
--
select * from work where topdate>='startdate' and 'startdate'<='enddate'
declare @stardate datetime
declare @enddate datetime
set @stardate=''
set @enddate=''
select * from work where topdate between @stardate and @enddate
---
insert into tb values(1, '2007/12/29 10:26:35', 'q')
insert into tb values(2, '2007/12/29 10:32:47', 'a')
insert into tb values(3, '2007/12/29 10:32:48', 'c')
insert into tb values(4, '2008/1/2 10:21:31', 's')
insert into tb values(5, '2008/1/2 10:24:36', 'd')
insert into tb values(6, '2008/1/2 10:25:31', 'f')
goselect * from tb where convert(varchar(19) , topdate , 120) >= '2008-01-02 00:00:00' and convert(varchar(19) , topdate , 120) <= '2008-01-02 23:59:59'
/*
id topdate name
----------- ----------------------- ----------
4 2008-01-02 10:21:31.000 s
5 2008-01-02 10:24:36.000 d
6 2008-01-02 10:25:31.000 f(3 行受影响)
*/select * from tb where convert(varchar(19) , topdate , 120) >= '2008-01-02 00:00:00' and convert(varchar(19) , topdate , 120) <= '2008-01-02 10:24:36'
/*
id topdate name
----------- ----------------------- ----------
4 2008-01-02 10:21:31.000 s
5 2008-01-02 10:24:36.000 d(2 行受影响)
*/drop table tb