日期:2014-05-18 浏览次数:20500 次
declare @tt datetime select @tt = date1 from A select * from b where date2>convert(datetime, convert(varchar, dateadd(day,-1,@tt) ,101) +' 20:00:00') and date2 <convert(datetime, convert(varchar, @tt,101) +' 12:00:00')
------解决方案--------------------
cdate(format( dateadd("d",-1,cdate("2008-11-25")) ,"yyyy-mm-dd") +" 20:00:00")
------解决方案--------------------
CREATE TABLE A (
date1 datetime
)
CREATE TABLE B (
date2 datetime
)
GO
INSERT INTO A VALUES('2008-11-25')
INSERT INTO B VALUES('2008-11-25 11:39:27')
INSERT INTO B VALUES('2008-11-25 12:39:27')
INSERT INTO B VALUES('2008-11-24 22:39:27')
INSERT INTO B VALUES('2008-11-24 12:39:27')
select ta.date1 dA,tb.date2 dB
from a ta left outer join b tb on datediff(day,ta.date1,tb.date2)=-1
where
datepart(hh,tb.date2)>20 and ta.date1=(
select top 1 date1 from a order by date1 desc
)
order by date2 asc
DROP TABLE A
DROP TABLE B
------解决方案--------------------
试试5楼的
呵呵
帮顶
------解决方案--------------------
ding