试试这个——
DECLARE @temp TABLE
(
[A-B_dim_id] INT
, a_vector NVARCHAR(50)
)
INSERT INTO @temp ([A-B_dim_id], a_vector)
VALUES (1234, '1.25,2.25,3.25')
DECLARE @temp2 TABLE
(
fact_id INT IDENTITY(1,1) PRIMARY KEY
, [A-B_dim_id] INT
, a_vector_id SMALLINT
, a_vector_value DECIMAL(10,2)
)
INSERT INTO @temp2 ([A-B_dim_id], a_vector_id, a_vector_value)
SELECT
[A-B_dim_id]
, ROW_NUMBER() OVER (PARTITION BY [A-B_dim_id] ORDER BY 1/0)
, t.c.value('.', 'DECIMAL(10,2)')
FROM (
SELECT
[A-B_dim_id]
, ID = CAST ('<t>' + REPLACE(a_vector, ',', '</t><t>') + '</t>' AS XML)
FROM @temp
) r
CROSS APPLY ID.nodes ('/t') t(c)
SELECT * FROM @temp2
输出 -
fact_id A-B_dim_id a_vector_id a_vector_value
----------- ----------- ----------- ---------------------------------------
1 1234 1 1.25
2 1234 2 2.25
3 1234 3 3.25