sql 按逗号拆分成多条数据

; with tt as
( select id,GaiZhangUserIDS= cast ( left (GaiZhangUserIDS,charindex( ',' ,GaiZhangUserIDS+ ',' )-1) as nvarchar(100)),
Split= cast (stuff(GaiZhangUserIDS+ ',' ,1,charindex( ',' ,GaiZhangUserIDS+ ',' ), '' ) as nvarchar(100)) from BD_InvoiceCorp where GaiZhangUserIDS is not null and GaiZhangUserIDS<>''
union all
select id,GaiZhangUserIDS= cast ( left (Split,charindex( ',' ,Split)-1) as nvarchar(100)),Split= cast (stuff(Split,1,charindex( ',' ,Split), '' ) as nvarchar(100)) from tt where split> '')

select id,GaiZhangUserIDS from tt order by id option (MAXRECURSION 0)

posted @ 2022-11-03 17:22  何华荣  阅读(704)  评论(0编辑  收藏  举报