Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
peace
Constraint Violating Yak Guru
420 Posts |
Posted - 2014-09-03 : 00:42:42
|
Can anyone help me on the logic. I would like to pull a data every 4 hours.select columnA from tableAthe columnA will consist lots of datetime value.would like to pull 00:00-04:00, 04:01-08:00, and so on..i tried something like this..declare @time timedeclare @condition timeset @time = CONVERT(VARCHAR(8),dateadd(hour,8,GETDATE()),108)set @condition = CONVERT(VARCHAR(8),dateadd(hour,8,GETDATE()),108)select @time, @conditionIf @condition < @timeBeginselect columnA from tableAwhere CONVERT(VARCHAR(8),columnA ,108)>= '00:00:00'and CONVERT(VARCHAR(8),columnA ,108)<= '04:00:00'EndElseBeginselect columnA from tableAwhere CONVERT(VARCHAR(8),columnA ,108)>= '04:01:00'and CONVERT(VARCHAR(8),columnA ,108)<= '08:00:00'EndElse'''' |
|
|
|
|
|
|