select a.c1+a.c2 from tA ,tB where tA.m =tB.nA m c1 1 a 2 b 3 cb n c2 1 001 2 002 3 003 ------------------------------------ 体验速度,体验CSDN论坛助手:http://community.csdn.net/Expert/TopicView.asp?id=4700683
create table a(col varchar(10)) insert a select 'a' union all select 'b' union all select 'c' union all select 'd' union all select 'e' create table b(col varchar(10)) insert b select '001' union all select '002' union all select '003' union all select '004' select id=identity(int),* into #a from a select id=identity(int),* into #b from b select #a.col+isnull(#b.col,'') from #a left join #b on #a.id=#b.id
create table A(aa nchar(10)) insert into a select 'a' union all select 'b' union all select 'c' union all select 'd' union all select 'e' create table b(bb nchar(10)) insert into b select '001' union all select '001' union all select '001' union all select '001' select * ,identity(int,1,1) as id into #a from a select * ,identity(int,1,1) as id into #b from b select rtrim(#a.aa)+isnull(ltrim(#b.bb),'') from #a left join #b on #a.id=#b.id
from tA ,tB
where tA.m =tB.nA
m c1
1 a
2 b
3 cb
n c2
1 001
2 002
3 003
------------------------------------
体验速度,体验CSDN论坛助手:http://community.csdn.net/Expert/TopicView.asp?id=4700683
insert a select 'a'
union all select 'b'
union all select 'c'
union all select 'd'
union all select 'e'
create table b(col varchar(10))
insert b select '001'
union all select '002'
union all select '003'
union all select '004'
select id=identity(int),* into #a from a
select id=identity(int),* into #b from b
select #a.col+isnull(#b.col,'') from #a left join #b on #a.id=#b.id
insert into a
select 'a'
union all
select 'b'
union all
select 'c'
union all
select 'd'
union all
select 'e'
create table b(bb nchar(10))
insert into b
select '001'
union all
select '001'
union all
select '001'
union all
select '001'
select * ,identity(int,1,1) as id into #a from a
select * ,identity(int,1,1) as id into #b from b
select rtrim(#a.aa)+isnull(ltrim(#b.bb),'') from #a left join #b
on #a.id=#b.id