Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

11
  • Please add your attempt and why it is not working for you (unexpected result, error message, ...). Here you can find the documentation with many examples.
    – Sander
    Commented Sep 14, 2020 at 13:09
  • @Sander i will but it's so basic Commented Sep 14, 2020 at 13:09
  • 2
    @Mr.AF that's not what you did. You created a new JSON string combining all results with FOR JSON PATH, then tried to parse it (and get the original data back) with OPENJSON. If you want to extract the value stored in someKey you can use SELECT JSON_QUERY(RawData,"$.someKey") from thatTable or something similar. For scalar values you can use JSON_VALUE Commented Sep 14, 2020 at 13:18
  • 2
    Nobody is. I used to be a SQL Server MVP and yet I always have to search for functions and names. In fact, my first comment mentioned JSON_VALUE because I forgot it only works with scalar values. OPENJSON is meant to parse complex JSON strings and return their contents as a table. You'll find the functions to query and modify JSON data in Validate, Query, and Change JSON Data with Built-in Functions Commented Sep 14, 2020 at 13:33
  • 1
    BTW I expect I'll forget that distinction by tomorrow. The more experienced one is, the more one uses docs, help and man pages. There's no way to remember every HTML tag, CSS rule, Javascript framework, ASP.NET technology and SQL Server feature and function. Commented Sep 14, 2020 at 13:37