SELECT StartTime,CONVERT(datetime,case when datepart(mi,StartTime)<30 then CONVERT(varchar(100), StartTime, 23)+ ' ' +datename(hh,StartTime)+':00:00' else CONVERT(varchar(100), StartTime, 23)+ ' ' +datename(hh,StartTime)+':30:00' end) as HourPart
FROM
WGS_MainCDR_201401
TEMP
GROUP BY StartTime,CONVERT(datetime,case when datepart(mi,StartTime)<30 then CONVERT(varchar(100), StartTime, 23)+ ' ' +datename(hh,StartTime)+':00:00' else CONVERT(varchar(100), StartTime, 23)+ ' ' +datename(hh,StartTime)+':30:00' end)
StartTime HourPart
2014-01-16 01:59:25.203 2014-01-16 01:30:00.000
2014-01-16 01:59:30.627 2014-01-16 01:30:00.000
2014-01-16 01:59:35.297 2014-01-16 01:30:00.000
2014-01-16 01:59:46.063 2014-01-16 01:30:00.000
2014-01-16 02:00:15.327 2014-01-16 02:00:00.000
2014-01-16 02:00:19.157 2014-01-16 02:00:00.000
2014-01-16 02:27:46.327 2014-01-16 02:00:00.000
2014-01-16 02:28:46.327 2014-01-16 02:00:00.000
2014-01-16 02:39:31.000 2014-01-16