---测试数据--- if object_id('[tb]') is not null drop table [tb] go create table [tb]([col] varchar(17)) insert [tb] select 'aaa,wwwww,tt' union all select 'qqqqqqqqq,u,iiiii'
---查询--- select substring(col,charindex(',',col)+1,len(col)-charindex(',',reverse(col))-charindex(',',col)) as col from [tb]---结果--- col ----------------- wwwww u(所影响的行数为 2 行)
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([col] varchar(17))
insert [tb]
select 'aaa,wwwww,tt' union all
select 'qqqqqqqqq,u,iiiii'
---查询---
select
substring(col,charindex(',',col)+1,len(col)-charindex(',',reverse(col))-charindex(',',col)) as col
from [tb]---结果---
col
-----------------
wwwww
u(所影响的行数为 2 行)
------------------------------------
BBBBBB
set @len = charindex(',','AAA,BBBBBBBB,C')
select substring('AAA,BBBBBBBB,C',@len + 1,charindex(',',stuff('AAA,BBBBBBBB,C',1,@len,'')) -1)