dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Jan 16, 2019

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Transfer Data with JSON in SQL Server

You can transfer data with JSON in SQL Server. Based on an SQL query, you can output the results into JSON format. Here is a small example:

DECLARE @JSONOutput NVARCHAR(MAX) =
   (SELECT  * FROM Students FOR JSON auto, INCLUDE_NULL_VALUES)
Print @JSONOutput;

This could potentially give the following result:

[
   {
      "StudentID":1,
      "StudentName":"Hannes",
      "EnrolDate":"2017-12-14T14:19:22.273"
   },
   {
      "StudentID":2,
      "StudentName":"Elmarie",
      "EnrolDate":"2017-12-13T13:19:22.273"
   },
   {
      "StudentID":3,
      "StudentName":"Kayla",
      "EnrolDate":"2017-12-15T15:19:22.273"
   }
]
Hannes du Preez
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Thanks for your registration, follow us on our social networks to keep up-to-date