Skip to content
Advertisement

How to loop array of objects from table column?

Table columns :

My table column details has json object like

I want to write a query which will give me records like below :

I tried with

RESULT WITH COUNT :

EXPECTED

Advertisement

Answer

To get all the objects from json array along with other columns you can use OpenJson() and Cross Apply as below:

Query:

Output:

id cnt name dob addr Name dob addr
1 2 luke 12-10-90 sample1 luke 12-10-90 sample1
1 2 sam 12-10-88 sample2 sam 12-10-88 sample2

db<>fiddle here

Your code is working @DLV. Please check. There were problem with data formatting.

Output:

ID (No column name) (No column name) (No column name)
1 luke 12-10-90 sample1

db<>fiddle here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement