我真的很感激别人的帮助 我是所有SQL-SSIS内容的新手 我在SQL中有以下表格:
我需要创建一个包含AreaPath列的列的表,并由分隔符\
解析
这意味着我的最终目标是:
一些重要的事情:
任何帮助将不胜感激 谢谢!
答案 0 :(得分:0)
然后以下工作
DECLARE @Delim NVARCHAR(32) = '\';
DECLARE @t TABLE ( AreaSK INT, AreaName NVARCHAR(100), AreaPath NVARCHAR(100))
INSERT INTO @t
(AreaSK, AreaName, AreaPath)
VALUES
(12188, 'Kryptonite', '\Kryptonite'),
(12191, 'SL_A', '\Kryptonite\SL_A'),
(12192, 'P_Bender', '\Kryptonite\SL_A\ART_APL\PG_Apollo\P_Bender'),
(12194, 'PG_Edison', '\Kryptonite\SL_A\ART_APL\PG_Apollo\P_Bender\test\PG_Edison')
SELECT PVT.AreaSK
, PVT.AreaName
, PVT.TeamProject
, PVT.AL
, PVT.ART
, PVT.PG
, PVT.P
, PVT.T
FROM
(
SELECT
T.AreaSK
, T.AreaName
, CASE
WHEN rn = 1 THEN 'TeamProject'
WHEN rn = 2 THEN 'AL'
WHEN rn = 3 THEN 'ART'
WHEN rn = 4 THEN 'PG'
WHEN rn = 5 THEN 'P'
WHEN rn = 6 THEN 'T'
END 'Headings'
, [Value]
FROM
(
SELECT T.AreaSK
, T.AreaName
, T.AreaPath
, AreaPath2 = RIGHT(T.AreaPath, LEN(T.AreaPath) - 1) --remove first '\'
FROM @t T
) T
CROSS APPLY
dbo.FN_SplitString_AB(T.AreaPath2, @Delim)
) T
PIVOT
(
MAX(Value)
FOR Headings IN ([T],[P],[PG],[ART],[AL],[TeamProject])
) PVT
输出