SQL 时间查询 - MS-SQL Server / 基础类
表名: date
cbstartdate cbenddate
2010-03-16 12:00:00.000 2010-05-17 17:45:23.000
2010-03-17 12:00:00.000 2010-05-18 23:45:55.000
2010-04-12 12:00:00.000 2010-05-18 23:44:06.000
2010-05-12 12:00:00.000 2010-05-18 23:46:05.000
2010-05-12 12:00:00.000 2010-05-18 23:46:05.000
2010-05-17 17:54:50.560 2010-05-18 23:03:40.000
2010-05-17 17:54:50.560 2010-05-18 23:03:40.000
cbstartdate 起始时间 cbenddate 结束时间
我想要查询 时间在cbstartdate 在2010-05-17 到 cbenddate 2010-05-18 之间的数据
SELECT * from date where cbstartdate>'2010-05-17' and cbenddate<'2010-05-19'
SQL code:
select * from [Table]
where convert(varchar(10),cbstartdate,120)='2010-05-17'
and convert(varchar(10),cbenddate,120)='2010-05-18'
SQL code:
--> 生成测试数据表: [date]
IF OBJECT_ID('[date]') IS NOT NULL
DROP TABLE [date]
GO
CREATE TABLE [date] ([cbstartdate] [datetime],[cbenddate] [datetime])
INSERT INTO [date]
SELECT '2010-03-16 12:00:00.000','2010-05-17 17:45:23.000' UNION ALL
SELECT '2010-03-17 12:00:00.000','2010-05-18 23:45:55.000' UNION ALL
SELECT '2010-04-12 12:00:00.000','2010-05-18 23:44:06.000' UNION ALL
SELECT '2010-05-12 12:00:
相关问答:
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
有这样一条SQL
Select Get_Costtaxrate(col1), Get_Tcostvalue(col1) from a
其中Get_Costtaxrate、Get_Tcostvalue都是函数,这两个函数里面都是查找一个大表,Get_Tcostvalue还需要调用Get_C ......
现在有一个部门表dept(部门名称,部门号。。)有一个人员表emp(姓名,人员编号,职位,薪资,部门)
emp表中的内容是这样的:
a 1 工程师 3000 软件部
b 2 普通员工 2000 硬件部
c 3 工程师 4000 硬件部
d ......