here ya goDeclare @times table (hr int, mn int)Insert Into @timesSelect 06, 41Union All Select 07, 11Union All Select 07, 41Union All Select 07, 58Union All Select 08, 13Union All Select 08, 28Union All Select 08, 40Union All Select 08, 43Union All Select 26, 11--Select * From @timesDeclare @times2 table (id int, hr int, mn int)Insert Into @times2 Select id = (Select count(*) From @times where hr = A.hr and mn <= A.mn), hr, mn From @times ASelect rowId = A.id, hr01 = (Select id from @times2 Where hr = 1 and id = A.id), hr02 = (Select id from @times2 Where hr = 2 and id = A.id), hr03 = (Select id from @times2 Where hr = 3 and id = A.id), hr04 = (Select id from @times2 Where hr = 4 and id = A.id), hr05 = (Select id from @times2 Where hr = 5 and id = A.id), hr06 = (Select id from @times2 Where hr = 6 and id = A.id), hr07 = (Select id from @times2 Where hr = 7 and id = A.id), hr08 = (Select id from @times2 Where hr = 8 and id = A.id), hr09 = (Select id from @times2 Where hr = 9 and id = A.id), hr10 = (Select id from @times2 Where hr = 10 and id = A.id), hr11 = (Select id from @times2 Where hr = 11 and id = A.id), hr12 = (Select id from @times2 Where hr = 12 and id = A.id), hr13 = (Select id from @times2 Where hr = 13 and id = A.id), hr14 = (Select id from @times2 Where hr = 14 and id = A.id), hr15 = (Select id from @times2 Where hr = 15 and id = A.id), hr16 = (Select id from @times2 Where hr = 16 and id = A.id), hr17 = (Select id from @times2 Where hr = 17 and id = A.id), hr18 = (Select id from @times2 Where hr = 18 and id = A.id), hr19 = (Select id from @times2 Where hr = 19 and id = A.id), hr20 = (Select id from @times2 Where hr = 20 and id = A.id), hr21 = (Select id from @times2 Where hr = 21 and id = A.id), hr22 = (Select id from @times2 Where hr = 22 and id = A.id), hr23 = (Select id from @times2 Where hr = 23 and id = A.id), hr24 = (Select id from @times2 Where hr = 24 and id = A.id), hr25 = (Select id from @times2 Where hr = 25 and id = A.id), hr26 = (Select id from @times2 Where hr = 26 and id = A.id)From (Select Distinct id From @times2) A
Corey