34,590
社区成员
发帖
与我相关
我的任务
分享
create table #tb1([DATATMP] varchar(10),[TIMETMP] varchar(10),[其它字段] varchar(10))
insert #tb1 select '2009-1-1','10:00:00','xxxx'
union all select '2009-3-1','10:05:00','xxxx'
union all select '2007-3-2','7:11:00','xxxx'
union all select '2009-3-2','11:21:00','xxxx'
union all select '2007-3-2','8:11:00','xxxx'
union all select '2007-3-3','9:52:00','xxxx'
union all select '2007-3-3','13:00:00','xxxx'
select * from #tb1 where cast(DATATMP as datetime)+cast([TIMETMP] as datetime)
between '2007-3-3 13:00:00' and '2009-03-02 8:11:00'
DATATMP TIMETMP 其它字段
---------- ---------- ----------
2009-1-1 10:00:00 xxxx
2009-3-1 10:05:00 xxxx
2007-3-3 13:00:00 xxxx
(3 行受影响)
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([DATATMP] varchar(10),[TIMETMP] varchar(10),[其它字段] varchar(10))
insert [tb] select '2009-1-1','10:00:00','xxxx'
union all select '2009-3-1','10:05:00','xxxx'
union all select '2007-3-2','7:11:00','xxxx'
union all select '2009-3-2','11:21:00','xxxx'
union all select '2007-3-2','8:11:00','xxxx'
union all select '2007-3-3','9:52:00','xxxx'
union all select '2007-3-3','13:00:00','xxxx'
go
select *
from tb
where cast(DATATMP as datetime)+cast([TIMETMP] as datetime)
between '2007-3-3 13:00:00' and '2009-03-02 8:11:00'
/*
DATATMP TIMETMP 其它字段
---------- ---------- ----------
2009-1-1 10:00:00 xxxx
2009-3-1 10:05:00 xxxx
2007-3-3 13:00:00 xxxx
(3 行受影响)
*/
select *
from tb
where cast(datatmp+' '+timetmp as datetime) between '2009-3-2 8:11:00' and '2007-3-3 13:00:00'