存储过程循环表里的一列数据,速度,效率高
如A表里有3列把第二列数据循环出来
如A表里有3列把第二列数据循环出来
解决方案 »
- 高手来!~~~调试一个SQL程序
- 向大家请教一个问题...
- 怎么用程序控制导出全表和数据的脚本呢sqlserver2008 express
- 提问——学VC的,数据库学到什么程度就可以了up有分(接分人请进)(邹建,水影接分)up有分!!
- 动态查询语句,查不出来
- 高手救我,恢复数据库时的Unicode问题,急!!!
- sql 列变行(我认为最难的了)
- 再问一个SQL语句
- 怎样才能使数据库变小?(请不吝赐教)
- 在SQL查询时怎样用日期作为where的限定条件?
- 服务器sql server2005数据库与本地sql server2005数据库数据同步
- 为什么用excel导入SQL server的数据表老出现问题
A列 B列 C列
a a a
d d d
e e e
把B列ade 打印出来
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 行受影响)*/
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 行受影响)*/
--游标
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