0

Is it possible to transform the following view :

enter image description here

to this structure ?

enter image description here

I've tried with cross join but I have no idea how to make a condition based on column name.

4

1 回答 1

2

您需要APPLY而不是JOIN能够访问外部列

SELECT t.Date, v.[1], v.[2], v.number
FROM Table t
CROSS APPLY (VALUES
    (t.[1], CAST(NULL AS int), 1),
    (NULL, t.[2], 2)
) v ([1], [2], number)
于 2021-01-08T15:13:07.077 回答