Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
create table #temp(id int identity(1,1),startdate datetime)insert into #temp(startdate)select '2011-05-11 16:06:53.323' union allselect '2011-05-16 23:06:53.323' union allselect '2011-05-12 03:06:53.323' union allselect '2011-05-17 01:06:53.323'expected output:ID startdateduration1 2011-05-11 00:001 2011-05-11 00:30. .. .. .1 2011-05-11 23.302 2011-05-16 00:002 2011-05-16 00:30. .. .. .2 2011-05-16 23.30like wise for all Id's i need to get 00:00 to 23.30 irresepctive of startdate timeThanks in advance...--Ranjit
jimf
Master Smack Fu Yak Hacker
2875 Posts
Posted - 2011-05-11 : 07:29:31
Do you want the nearest 30 minute interval to each startdate, or just an output of 30 minute intervals?JimEveryday I learn something that somebody else already knew
Ranjit.ileni
Posting Yak Master
183 Posts
Posted - 2011-05-11 : 07:42:46
Hi jimf ,Thanks for u r reply...it just output of 30 min intervals..I did using cte
;with cte as(select id ,convert(datetime,CONVERT(VARCHAR(15), startdate, 112)) as datestartfrom #temp union allselect c.id ,c.datestart+'00:30:00' as day1from cte c join #temp r on r.id=c.idwhere dateadd(minute,1410,convert(datetime,CONVERT(VARCHAR(15), r.startdate, 112)))>c.datestart )select * from cteorder by id