Sql t数据中有一些异常值,这使我同意约翰·贝尔的解决方案。 +---------+----------------+ | ItemNum | Substitutes | +---------+----------------+ | ABCD | X

Sql t数据中有一些异常值,这使我同意约翰·贝尔的解决方案。 +---------+----------------+ | ItemNum | Substitutes | +---------+----------------+ | ABCD | X,sql,sql-server,excel,ms-access,Sql,Sql Server,Excel,Ms Access,t数据中有一些异常值,这使我同意约翰·贝尔的解决方案。 +---------+----------------+ | ItemNum | Substitutes | +---------+----------------+ | ABCD | XXXX/YYYY/ZZZZ | | PQRS | AAAA/BBBB/CCCC | +---------+----------------+ +---------+------------+ | ItemNum | Substitute

t数据中有一些异常值,这使我同意约翰·贝尔的解决方案。
+---------+----------------+
| ItemNum |  Substitutes   |
+---------+----------------+
| ABCD    | XXXX/YYYY/ZZZZ |
| PQRS    | AAAA/BBBB/CCCC |
+---------+----------------+
+---------+------------+
| ItemNum | Substitute |
+---------+------------+
| ABCD    | XXXX       |
| ABCD    | YYYY       |
| ABCD    | ZZZZ       |
| PQRS    | AAAA       |
| PQRS    | BBBB       |
| PQRS    | CCCC       |
+---------+------------+
SELECT T1.ItemNum, T2.mySplits as Substitute
FROM
 (
  SELECT *,
  CAST('<X>'+replace(T.Substitutes,'/','</X><X>')+'</X>' as XML) as my_Xml 
  FROM Table1 T
 ) T1
 CROSS APPLY
 ( 
 SELECT my_Data.D.value('.','varchar(50)') as mySplits
 FROM T1.my_Xml.nodes('X') as my_Data(D)
 ) T2
select ItemNum, substring(substitutes, 1, 4) as substitute
from staging
where substitutes is not null
union all
select ItemNum, substring(substitutes, 6, 4) as substitute
from staging
where substitutes like '%/%'
union all
select ItemNum, substring(substitutes, 10, 4) as substitute
from staging
where substitutes like '%/%/%'
select ItemNum, substitute1 as substitute
from staging
where substitute1 is not null
union all
select ItemNum, substitute2 as substitute
from staging
where substitute2 is not null
union all
select ItemNum, substitute3 as substitute
from staging
where substitute3 is not null
=OFFSET($A$2, INT((ROW(1:1)-1)/3),0)
=MID(OFFSET($A$2, INT((ROW(1:1)-1)/3), 1), MOD((ROW(1:1)-1)*5+1,15), 4)