This question already has answers here:
Deconstructing JSON array within a JSON SQL Server (2 answers)
How to use OPENJSON to concatenate json Array in a column of a table (1 answer)
How to concatenate text from multiple rows into a single text string in SQL Server (48 answers)
Closed 8 days ago.
I'm trying to read data from a table who has multiple columns and one of them is JSON data. Inside this JSON there is an array of JSON's that I want to get one specific value.
The JSON looks like this:
{
"FirstName": "Carlos",
"LastName": "Perez",
"PhoneNumbers": [{
"PhoneNumber": "123456789"
},
{
"PhoneNumber": "987654321"
}]
}
What I want is to read this JSON column so it gives me only the phones numbers.
I want to get a result like this:
| Id | Column 1 | Column 2 | JSON Column |
| ------------ | ------------ | ------------ | ------------ |
| 1 | Value 1 | Value 2 | 123456789, 987654321 |
1条答案
按热度按时间b4lqfgs41#
Your question can be improved by including a snippet of what you've done/tried and perhaps the challenge with that you can get tailored help with context, in any case, here's a
SQL
query to achieve your desired result.Remember to replace
YourTable
with the actual name of your table andYourJSONColumn
with the name of your JSON columnEdit: Optimising the query