有这样一个需求:

sql拆分查询

临时表sql:

create table #AA
(
   ID int,
   Name nvarchar(20)
)

insert #AA
select 1,'苏州/上海/温州'
union all
select 2,'南京'
union all
select 3,'北京/连云港'

方法:

 1 with hh as
 2  (select ID,
 3  Name=cast(left(Name,charindex('/',Name+'/')-1) as nvarchar(100)),
 4  Split=cast(stuff(Name+'/',1,charindex('/',Name+','),'') as nvarchar(100)) 
 5  from (SELECT ID,Name FROM #AA) t
 6  union all
 7  select ID,
 8  Name=cast(left(Split,charindex('/',Split)-1) as nvarchar(100)),
 9  Split= cast(stuff(Split,1,charindex('/',Split),'') as nvarchar(100)) from hh where split>'')
10 
11  select ID,Name from hh group by ID,Name
View Code

相关文章:

  • 2021-06-29
  • 2021-08-26
  • 2021-06-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-13
  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
相关资源
相似解决方案