declare @a varchar(1000)
set @a=' select '''+replace(@a,',',''' union all select ''')+''''
exec('insert table(fiele) '+@a)

解决方案 »

  1.   

    declare @s varchar(100)
    set @s='A,B,C'select 拆分结果=substring(@s,b.id,charindex(',',@s+',',b.id)-b.id)
    from(select name=@s) a join(
    select id=a.id+b.id+1
    from(
    select id=0 union all select 1
    union all select id=2 union all select 3
    union all select id=4 union all select 5
    union all select id=6 union all select 7
    union all select id=8 union all select 9
    ) a,(
    select id=0 union all select 10
    union all select id=20 union all select 30
    union all select id=40 union all select 50
    union all select id=60 union all select 70
    union all select id=80 union all select 90
    ) b
    ) b on substring(','+name,b.id,1)=','/*--拆分结果
    拆分结果                                      
    ----------------------------------------------- 
    A
    B
    C(所影响的行数为 3 行)
    --*/
      

  2.   

    b.id
    a.id
    是什么来的?