22,209
社区成员
发帖
与我相关
我的任务
分享
--游标
declare @b varchar(10)
declare tempcur cursor
for select b from tb
open tempcur
fetch next from tempcur into @b
while @@fetch_status = 0
begin
print @b
fetch next from tempcur into @b
end
close tempcur
deallocate tempcur
create table tb(a varchar(10),b varchar(10),c varchar(10))
insert into tb select 'k','a','q'
insert into tb select 'k','d','q'
insert into tb select 'k','e','q'
go
select distinct replace(b,' ','') from(
select stuff((select ' '+b from tb for xml path('')),1,1,'') b from tb
)t
go
drop table tb
/*
ade
(1 行受影响)
*/
create table tb(a varchar(10),b varchar(10),c varchar(10))
insert into tb select 'a','a','a'
insert into tb select 'd','d','d'
insert into tb select 'e','e','e'
go
select distinct replace(b,' ','') from(
select stuff((select ' '+b from tb for xml path('')),1,1,'') b from tb
)t
go
drop table tb
/*
ade
(1 行受影响)
*/
select B列 from 表1