Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.
I started to dig into JSON queries recently, and as I continued to experiment with JSON, this struck me as strange. Why is there a NULL in the result?
The path looks right. This appears to be somewhere I ought to get a result back. As I looked up the JSON_QUERY documentation, and it says I get an object or array back. I’d somewhat expect that position, while containing a single value, could be seen as an object of
{“setter”}
The fact that I need to know I have a single value here seems like poor design. If the document changes, perhaps someone might enter this:
DECLARE @json NVARCHAR(1000)
= N'
{ "player": {
"name" : "Sarah",
"position" : "setter, DS"
},
"team":"varsity"
}
';
In this case, a JSON_VALUE would fail, while a JSON_QUERY wouldn’t work in the first example above. This means that I need to modify my code based on documents.
I don’t like this, but I need to know this, so if you work with JSON, make sure you know how the functions work.
While writing the previous post, I changed one of the function calls and got the NULL. I had to fix things for the other post, but I kept the query and then spent about 10 minutes writing this one to show a little thought into the language.
You can easily take something you are confused about, made a mistake doing, or wonder about and write your own post.
The post No Scalars with JSON_QUERY–#SQLNewBlogger appeared first on SQLServerCentral.
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…