张三       aa,bb,cc
  李四       aa,cc
  张三       aa转化成  张三  aa
  张三  bb
  张三  cc
  李四  aa
  李四  cc 
  张三  aa 
要有重复的

解决方案 »

  1.   

    ---测试数据---
    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb]([col1] varchar(4),[col2] varchar(8))
    insert [tb]
    select '张三','aa,bb,cc' union all
    select '李四','aa,cc' union all
    select '张三','aa'
     
    ---查询---
    select 
     a.Col1,COl2=substring(a.Col2,b.number,charindex(',',a.Col2+',',b.number)-b.number) 
    from 
      tb a,master..spt_values b
    where
      b.type='P'
    and
      charindex(',',','+a.Col2,b.number)=b.number---结果---
    Col1 COl2
    ---- --------
    张三   aa
    张三   bb
    张三   cc
    李四   aa
    李四   cc
    张三   aa(6 行受影响)