22,209
社区成员
发帖
与我相关
我的任务
分享
use Test
go
create table T(code int,value nvarchar(20))
insert T select 1,'01,02,03'
insert T select 2,'04,05'
go
select top 100 ID=identity(int,1,1) into # from sysobjects a ,syscolumns b--辅助表
go
select
T.code,[value]=substring([value],ID,charindex(',',[value]+',',ID)-ID)
from
T
cross join
# T2
where
ID<=(len(value+','))and
charindex(',',','+value,ID)=ID
code value
----------- --------------------
1 01
1 02
1 03
2 04
2 05
(所影响的行数为 5 行)