案例:
預訂會議室時判斷提交預訂的時間段是否與已經預訂的時間段衝突
create
table
roombookinfo(id
intnot
null,
title
nvarchar
(10)
notnull,
begintime
datetime
notnull,
endtime
datetime
notnull
)select
*from
roombookinfo
truncate
table
roombookinfo
insert
into
roombookinfo
values
(1,'
會議一'
,'2010-10-15 00:01:00'
,'2010-10-15 00:03:00'
);insert
into
roombookinfo
values
(2,'
會議二'
,'2010-10-15 00:05:00'
,'2010-10-15 00:08:30'
);insert
into
roombookinfo
values
(3,'
會議三'
,'2010-10-16 00:12:00'
,'2010-10-17 00:15:00'
);--
網上找的解決方案
declare
@btime
nvarchar
(50)
declare
@etime
nvarchar
(50)
set@btime
='2010-10-13 00:04:30'
set@etime
='2010-10-18 00:07:30'
select
*from
roombookinfo
where
((@btime
>=
begintime
and@btime
<
endtime)or
(@btime
<
endtime
and@etime
>
endtime)or
(@btime
<=
begintime
and@etime
>
begintime
))--
根據網上打的資料自己寫的(顯然沒有上面的精闢)
--declare@btime nvarchar(50)
--declare@etime nvarchar(50)
set@btime
='2010-10-12 00:04:30'
set@etime
='2010-10-18 00:09:30'
select
*from
roombookinfo
where
(@btime
between
begintime
andendtime)or
(@etime
between
begintime
andendtime)or
(begintime
between
@btime
and@etime)or
(endtime
between
@btime
and@etime)--
其它的用法
declare
@anvarchar
(50)
declare
@bnvarchar
(50)
set@a
='2010-10-15 00:04:30'
set@b
='2010-10-17 00:09:30'
select
case
(select
count
(*)from
roombookinfo
where(@a
between
begintime
andendtime)or
(@bbetween
begintime
andendtime)or
(begintime
between
@aand@b)
or(endtime
between
@aand@b)
)when 0 then
'會議未建立
'when 1 then
'有乙個會議
'else
'有很多重複的會議
'end
判斷乙個時間段與一組時間段是否有相交
兩個時間段相交分為三種情況,如下圖所示 圖中的數字為時間點的id號 乙個時間段有開始時間點start和結束時間點end表示。1.設定這組時間段彼此互不相交,由陣列列表arraylist表示 timelist,timelist依次加入所有時間段的起末時間點。2.把要判斷的這條時間段的起末時間點依次加入...
判斷乙個物件是否是另乙個的字首
題目 給出兩個int型的vector物件,編寫程式判斷乙個物件是否是另乙個物件的字首。如果兩個vector物件的長度不相同,假設較短的vector物件長度為n,則只對這兩個物件的前面n個元素做比較。例如,對於 0,1,1,2 和 0,1,1,2,3,5,8 這兩個vector,你的程式應該返回tru...
oracle中判斷乙個串中是否包含另乙個串
select decode instr corporateaaaa floor aaaa 0,0,1 from dualinstr方法的格式為 instr 源字串,目標字串,起始位置,匹配序號 例如 instr corporate floor or 3,2 中,源字串為 corporate floo...