34,590
社区成员
发帖
与我相关
我的任务
分享
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
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
*/