Is it possible to pivot OPENJSON data for multiple rows in T-SQL (on SQL Server 2022).
I have a case like below, it works fine for single ID (eg. CustID=111). Surely I can go this route processing each row, but probably there is a way to make it more compact and faster. Even free Copilot doesn't know if this possible
Appreciate your feedback. Please refer to self containing snippet below.
declare @json nvarchar(max);
with t as (
select 111 CustID, '{ "xNotes": "Not shipped", "xManager": "Pavel", "xType": "1"}' DataEx
union all
select 222 CustID, '{ "xNotes": "Pending", "xManager": "Maria", "xType": "2"}'
)
select @json = DataEx from t -- where Custid = 111;
select [key], [value], [type] --, CustID ???
from openjson(@json);
-- output for single row:::
-- key value type
-- xNotes Pending 1
-- xManager Maria 1
-- xType 2 1
And this is desired output:
