Langsung ke konten utama

How Produce You Lot Furnish Json Formatted Reply To A Sql Query?

JSON is supported inward SQL Server too it is real slow to obtain JSON formatted reply from a interrogation easily. For example,

piece connected to Northwind database you lot acquire the JSON formatted information past times running a interrogation such equally this 1 using the Products table:
---------------------------------
SELECT        ProductName, QuantityPerUnit, UnitPrice
FROM            Products FOR JSON Auto;

---------------------------------
The reply volition hold out equally shown:


JSON_0

You could besides provide a unmarried row of information equally shown past times running this query:
-----------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
WHERE ProductID=5
For JSON AUTO

-------------------------


JSON_1


The effect comes inward an array fifty-fifty if the returned information is simply 1 row.

You could take the array wrapper ([ ]) surrounding the effect develop past times the next query:
-------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
For JSON AUTO, WITHOUT_ARRAY_WRAPPER

---------------------------------------

JSON_2

Notice that the array wrapper is gone inward the effect set.

You tin cease farther qualify where the information (Which table, for example) past times adding a 'root' chemical gene past times issuing this query:
------------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
For JSON AUTO, Root('Products')

------------------------

JSON_3

You are non allowed to purpose WITHOUT_ARRAY_WRAPPER too Root inward the same sql interrogation because you lot acquire the next message, if you lot do:

Msg 13620, Level 16, State 1, Line 5
ROOT selection too WITHOUT_ARRAY_WRAPPER selection cannot hold out used together inward FOR JSON. Remove 1 of these options.


I am using SQL Server 2016 Developer's edition on my Windows 10 Pro laptop.

If you lot are novel to JSON read the following:

https://hlthnworkout.blogspot.com//search?q=how-do-you-work-with-javascript-object

If you lot are motivated to larn in that place are to a greater extent than here:

https://hlthnworkout.blogspot.com/search?q=json

Komentar

Postingan populer dari blog ini

What Happenned To My Restore Points Inward Windows 10?

They disappeared because in that place was an automatic update of the operating system. One creates organisation restore points to become dorsum inward representative in that place is a problem. Typically when you lot run into around rpoblem you lot would desire to become dorsum to a restore indicate you lot accept created. The restore indicate would notwithstanding last available to you lot were it non for the automatic Windows Updates. It would last squeamish if in that place is a agency of having OS on ane drive that does non update (so restore points are available) as well as OS on the other that tin update as well as install the better(?) code.

Download As Well As Install Written Report Builder For Sql Server 2016

Report Builder is a highly productive, stand-alone tool for authoring reports as well as deploying them on configured Microsoft Reporting services study servers. It tin purpose information from dissimilar kinds of information sources to produce  a multifariousness of reports, from difficult copies to spider web based reporting. Report Builder three Details: -------------- Version: 14.0.344.82 File Name: ReportBuilder3.msi Date Published: 3/9/2017 File Size: 22.6 MB ----------------- You require Microsoft .NET Framework 4.5 . The retentiveness as well as CPU requirements are average. This is supported on  the next OSs: Windows 10 , Windows 7, Windows 8, Windows 8.1, Windows Server 2008 R2, Windows Server 2008 R2 SP1, Windows Server 2012, Windows Server 2012 R2 download from here: https://www.microsoft.com/en-us/download/confirmation.aspx?id=53613 Please review the before versions of Report builder inwards 2 of my published books here: The minute ma...

What Version Of Sql Server Information Tools Tin Forcefulness Out Endure Used Amongst Visual Studio Community?

The recommended version of VS Community to purpose the latest SSDT is Visual Studio 2015. The version of SSDT amongst Visual Studio 2015 Update iii is  14.0.60519.0 . With this version of SSDT you lot tin usage the next types of Business Intelligence projects for which you lot tin discovery the templates inwards the New Project Menu shown here: Analysis Services Project templates: Integration Services Project templates:   Reporting Services Project templates I am non certain if at that spot are templates online for Business Intelligence projects. I tried too did non discovery any.