遍历添加时间
表A,字段:date1 值.2008-11-25 (遍历表A时间记录)
表B,字段:date2 值2008-11-25 12:39:27
值2008-11-24 22:39:27
值2008-11-24 12:39:27
希望实现:表A,date1字段的时间 既;2008-11-25
获取,该字段相应表B,大于此时间前一天的 20点之后,并且是当天12点之前,插入的数据,,,
即以上表b只有第二条满足,即:2008-11-24 22:39:27
这该如何实现。!!!!!!!!!!!!
[解决办法]
select * from b
where
date2>convert(datetime, convert(varchar, dateadd(day,-1,'2008-11-25') ,101) +' 20:00:00')
and
date2<convert(datetime, convert(varchar, '2008-11-25' ,101) +' 12:00:00')
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/
[解决办法]
declare @tt datetimeselect @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