Использование SQL Server 2005
Tabl1
ID Date Intime Outtime
001 20101201 080000 180000
001 20101202 210000 060000
001 20101203 180000 090000
001 20101204 100000 170000
....
.
Date Datatype is nvarchar
Intime, Outtime datatype is nvarchar
Intime, Outtime Format: HHMMSS
Из таблицы 1 я хочу сделать еще одно имя столбца как NextDate.
В следующем столбце даты должна отображаться следующая дата столбца даты со следующим условием
If Outtime is Greater than Intime then it should display the next date
If outtime is less than intime then it should display the same date
Ожидаемый результат
ID Дата Интервал Время ожидания Следующая дата
001 20101201 080000 180000 20101201 (Outtime is less than Intime)
001 20101202 210000 060000 20101203 (Outtime is greater than Intime)
001 20101203 180000 090000 20101204 (Outtime is greater than Intime)
001 20101204 100000 170000 20101204 (Outtime is less than Intime)
....
Как сделать запрос для вышеуказанного условия.
Нужна помощь по запросу.