I am trying to do a pivot in SQL Server wherein I need to pivot the following table:
key value
column1 billy
column2 billy@billy.com
column5 NULL
column6 false
column9 true
I want the values in the "key" column to be the column headers. Another problem here is that I am using a CROSS APPLY to generate this table from another table. I start with:
select * from jtable cross apply openjson(json)
which results in the table format shown above.
If I don't use the cross apply, I get a table that looks like this:
ID json
1 "column1":billy, "column2":billy@billy.com
2 "column1":steve, "column2":steve@etc.com
So I'm trying to end up with a table that looks like this:
column1 column2 column3
billy billy@billy.com false
steve steve@etc.com false