select 日期1 from 表1 union select 日期2 from 表2 union select 日期3 from 表3 order by 日期1
select 日期1 as 日期 from table union select 日期2 from table union select 日期3 from table
drop table #t go create table #t(日期1 datetime,日期2 datetime,日期3 datetime) insert into #t select '2007-5-3','2007-5-3','2007-5-3' union all select '2007-5-4',null,null union all select '2007-5-5',null,'2007-5-5' union all select null,'2007-5-6','2007-5-6'select isnull(isnull(日期1,日期2),日期3) from #t/* ------------------------------------------------------ 2007-05-03 00:00:00.000 2007-05-04 00:00:00.000 2007-05-05 00:00:00.000 2007-05-06 00:00:00.000(所影响的行数为 4 行) */
select distinct 日期 from ( select 日期1 日期 from tb1 where 日期1 is not null union all select 日期2 日期 from tb2 where 日期2 is not null union all select 日期3 日期 from tb3 where 日期3 is not null ) order by 日期
union
select 日期2 from 表2
union
select 日期3 from 表3
order by 日期1
union
select 日期2 from table
union
select 日期3 from table
go
create table #t(日期1 datetime,日期2 datetime,日期3 datetime)
insert into #t
select '2007-5-3','2007-5-3','2007-5-3'
union all select '2007-5-4',null,null
union all select '2007-5-5',null,'2007-5-5'
union all select null,'2007-5-6','2007-5-6'select isnull(isnull(日期1,日期2),日期3) from #t/*
------------------------------------------------------
2007-05-03 00:00:00.000
2007-05-04 00:00:00.000
2007-05-05 00:00:00.000
2007-05-06 00:00:00.000(所影响的行数为 4 行)
*/
(
select 日期1 日期 from tb1 where 日期1 is not null
union all
select 日期2 日期 from tb2 where 日期2 is not null
union all
select 日期3 日期 from tb3 where 日期3 is not null
)
order by 日期
怎么显示
03 05 2007 12:00AM
2007-5-04
2007-5-05
2007-5-06
07 05 2007 12:00AM