select id,值=substring(aa,id,1)
from(select aa='china') a,(
select id=a.id+b.id+c.id+d.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,(
select id=0 union all select 100
union all select id=200 union all select 300
union all select id=400 union all select 500
union all select id=600 union all select 700
union all select id=800 union all select 900
) c,(
select id=0 union all select 1000
union all select id=2000 union all select 3000
union all select id=4000 union all select 5000
union all select id=6000 union all select 7000
union all select id=8000 union all select 9000
) d
) b where b.id<=len(aa)
order by id

解决方案 »

  1.   

    --上面的语句可以处理的最大字符串长度为10000(实际上SQL中字符串最大长度为8000)/*--测试结果
    id          值    
    ----------- ---- 
    1           c
    2           h
    3           i
    4           n
    5           a(所影响的行数为 5 行)
    --*/
      

  2.   

    --测试:
    declare @a varchar(20),@s varchar(8000),@i  int
    set @a = 'china'
    set @s = ''
    set @i = 1
    while @i <=len(@a)
    begin
    select @s = @s + (case when @s = '' then 'select ' else ' union all select ' end)+cast(@i as varchar)+',''' +substring(@a,@i,1)+''''
    set @i = @i+1
    end
    --print @s
    exec(@s)
                     
    ----------- ---- 
    1           c
    2           h
    3           i
    4           n
    5           a
      

  3.   

    马可,楼主是要求一个SQL语句哦.哈哈