存储过程循环表里的一列数据,速度,效率高
如A表里有3列把第二列数据循环出来

解决方案 »

  1.   

    表1
    A列    B列   C列
    a     a     a
    d     d     d
    e     e     e   
    把B列ade 打印出来 
      

  2.   

    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 行受影响)*/
      

  3.   

    朋友,这个问题必须用到whlie循环,在循环里还要取到B列的没一个数据进行处理
      

  4.   

    你觉得这样处理不是获得b 列的所有值吗?
    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 行受影响)*/
      

  5.   


    --游标
    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