Мне показалось, что так будет кошернее.
Это кусок черновика.
..............
declare @cur_table table( caseID varchar(50), d datetime);
..............
declare f cursor scroll local
for select caseID from @t
open f
while 1=1
begin
fetch next from f
into @fn
insert into @cur_table
select caseID, none_d d from @t where caseID=@fn
union all
select caseID, simple_d d from @t where caseID=@fn
union all
select caseID, complex_d d from @t where caseID=@fn
union all
select caseID, man_d d from @t where caseID=@fn
union all
select caseID, pol_d d from @t where caseID=@fn
--select caseID, max(d) from @cur_table group by caseID
--update @t set inv_d=( select max(d) from @cur_table where @t.caseID=@cur_table.caseID)
if @@fetch_status <> 0 break
end
close f
deallocate f
select caseID, cast(convert(char(8), max(d), 112) as int) d into #r from @cur_table group by caseID
ПыСы.Работает как надо.