create table Datetimes
(
Date1 datetime,
Date2 datetime,
Date3 datetime,
Date4 datetime,
Date5 datetime
)
declare @i int
set @i = 1000
while (@i>0)
begin
insert into Datetimes values(DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0),DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0),DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0),DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0),DATEADD(day, (ABS(CHECKSUM(NEWID())) % 65530), 0))
set @i = @i - 1
end
go
select
max(Date) from
(
select max(Date1) a1 ,max(Date2) a2, max(Date3) a3, max(Date4) a4, max(Date5) a5 from Datetimes
)
t
unpivot
(
Date for Dates in ([a1],[a2], [a3],[a4],[a5])
) as UnPvt