Skip to content

Instantly share code, notes, and snippets.

@rruntsch
Created March 31, 2022 21:02
Show Gist options
  • Save rruntsch/68a1a4807cc64ce04f01bc9900e3ebe8 to your computer and use it in GitHub Desktop.
Save rruntsch/68a1a4807cc64ce04f01bc9900e3ebe8 to your computer and use it in GitHub Desktop.
Query data from SQL Server and write its results in the JSON format.
-- File: customer_location_json.sql
-- Date: March 31, 2022
-- Author: Randy Runtsch
-- Description: Get the names and location (city, state or province,
-- postal code, and country or region name
-- for all customers in the AdventureWorks2019 database.
-- Return the data in JSON format.
USE AdventureWorks2019;
GO
SELECT
-- TOP (5)
BusinessEntityID
, City
, StateProvinceName
, PostalCode
, CountryRegionName
FROM [AdventureWorks2019].[Sales].[vIndividualCustomer]
ORDER BY
CountryRegionName
, StateProvinceName
, City
FOR JSON PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment