日期:2014-05-17 浏览次数:20566 次
create table #tb(col varchar(100))
insert into #tb
select '123,11,74512'
union all select '1354534,1545'
union all select '456465'
union all select NULL
select case when charindex(',',col)>0 then left(col,charindex(',',col)-1) else col end
from #tb
drop table #tb
/*
123
1354534
456465
NULL
*/
create table #tb(col varchar(100))
insert into #tb
select '123,11,74512'
union all select '1354534,1545'
union all select '456465'
union all select NULL
select left(col,charindex(',',col+',')-1) from #tb