create table tb(id int, value varchar(1)) insert into tb values(1 , 'a') insert into tb values(2 , 'b') insert into tb values(3 , 'c') insert into tb values(4 , 'd') goselect m.value + n.value from tb m , tb n where m.id < n.iddrop table tb /*
---- ab ac bc ad bd cd(所影响的行数为 6 行)*/
--你cd不需要? create table tb(id int, value varchar(1)) insert into tb values(1 , 'a') insert into tb values(2 , 'b') insert into tb values(3 , 'c') insert into tb values(4 , 'd') go--方法一 select m.value + n.value from tb m , tb n where m.id < n.id --方法二 select m.value + n.value from tb m , tb n where m.id < n.id drop table tb /*
---- ab ac bc ad bd cd(所影响的行数为 6 行)*/
declare @t table(id int, [value] varchar(10))
insert @t select 1 , 'a' insert @t select 2 , 'b' insert @t select 3 , 'c' insert @t select 4 , 'd' select a.value+b.value col from @t a left join @t b on a.[value]<b.[value] where b.[value] is not nullcol -------------------- ab ac bc ad bd cd(6 行受影响)这样可以吗?
drop table #tb create table #tb(id int identity(1,1),value varchar(10)) insert into #tb(value) values('a') insert into #tb(value) values('b') insert into #tb(value) values('c') insert into #tb(value) values('d') declare @s varchar(1000) set @s='' select @s=@s+a.value+b.value +' ' from #tb a,#tb b where a.id<>b.id print @s/* ba ca da ab cb db ac bc dc ad bd cd */
insert into tb values(1 , 'a')
insert into tb values(2 , 'b')
insert into tb values(3 , 'c')
insert into tb values(4 , 'd')
goselect m.value + n.value from tb m , tb n where m.id < n.iddrop table tb /*
----
ab
ac
bc
ad
bd
cd(所影响的行数为 6 行)*/
create table tb(id int, value varchar(1))
insert into tb values(1 , 'a')
insert into tb values(2 , 'b')
insert into tb values(3 , 'c')
insert into tb values(4 , 'd')
go--方法一
select m.value + n.value from tb m , tb n where m.id < n.id
--方法二
select m.value + n.value from tb m , tb n where m.id < n.id
drop table tb /*
----
ab
ac
bc
ad
bd
cd(所影响的行数为 6 行)*/
insert @t select 1 , 'a'
insert @t select 2 , 'b'
insert @t select 3 , 'c'
insert @t select 4 , 'd' select a.value+b.value col from @t a left join @t b on a.[value]<b.[value] where b.[value] is not nullcol
--------------------
ab
ac
bc
ad
bd
cd(6 行受影响)这样可以吗?
create table #tb(id int identity(1,1),value varchar(10))
insert into #tb(value) values('a')
insert into #tb(value) values('b')
insert into #tb(value) values('c')
insert into #tb(value) values('d')
declare @s varchar(1000)
set @s=''
select @s=@s+a.value+b.value +' '
from #tb a,#tb b
where a.id<>b.id
print @s/*
ba ca da ab cb db ac bc dc ad bd cd
*/
需要拿到表的全部记录循环去做。