case when else;具体查帮助

解决方案 »

  1.   

    用字符串处理函数,结合distinct语句就行了.
    begin tran--创建数据测试环境
    create table tb(abc varchar(10))
    insert into tb
    select 'aaa,bbb,ss'
    union all select 'aaa'
    union all select 'wwww,kjl'
    union all select 'fsfff'
    union all select 'wwww'
    union all select 'ff,ff'--得到结果
    select distinct case charindex(',',abc) when 0 then abc
    else left(abc,charindex(',',abc)-1) end as abc
    from tbrollback tran
      

  2.   

    select distinct case when charindex(',',ABC)=0 then ABC else left(ABC,charindex(',',ABC)-1) end from tableName