日期:2014-05-18 浏览次数:20525 次
if exists(select * from sysobjects where name in('t1','t2','t3'))
drop table t1,t2,t3
create table t1(id integer ,f1 varchar(10),f2 varchar(10), f3 varchar(10))
create table t2(id integer ,fd1 varchar(10),fd2 varchar(10), fd3 varchar(10))
create table t3(id integer ,fed1 varchar(10),fed2 varchar(10), fed3 varchar(10))
insert into t1(id ,f1,f2,f3)
select 01, 'hh', 'gg', 'jj'
union select
02, 'kk', 'gt', 'ft'
insert into t2(id ,fd1,fd2,fd3)
select 01, 'hh', 'gg', 'jj'
union select
02, 'kk', 'gt', 'ft'
insert into t3(id ,fed1,fed2,fed3)
select 01, 'hh', 'gg', 'jj'
union select
02, 'kk', 'gt', 'ft'
if exists(select * from sysobjects where name='t')
drop table t
create table t(id integer ,c1 varchar(50),c2 varchar(50),c3 varchar(50),falg varchar(1))
insert into t(id,c1,c2,c3,falg)
select id,f1,f2,f3,'1' from t1
insert into t(id,c1,c2,c3,falg)
select id,' '+fd1,fd2,+fd3,'2' from t2
insert into t(id,c1,c2,c3,falg)
select id,' '+fed1,fed2,fed3,'3' from t3
select case when falg='1' then id else '' end,c1,c2,c3
from t order by id,falg
drop table t