Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include OPENJSON in View?

My JSON object is stored in the table (single cell). Right now, I'm reading the cell and saving the value to @json NVARCHAR(MAX)

SELECT *
FROM OPENJSON ( @json )  
WITH (...)

, but that obviously doesn't work in views. How can I do something like this?

SELECT *
FROM OPENJSON ( select top 1 json_object from json_raw )  
WITH (...)
like image 478
Mara Avatar asked Jun 16 '26 06:06

Mara


1 Answers

You can use cross apply to apply openjson() to each and every row of your table:

create view jsonview as
select x.*
from json_raw j
cross apply openjson(j.json_object) with (...) as x
like image 168
GMB Avatar answered Jun 18 '26 00:06

GMB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!