Skip to content

Instantly share code, notes, and snippets.

@rruntsch
Last active March 31, 2022 21:04
Show Gist options
  • Save rruntsch/36495ae585247fb88434ec92065f7f5b to your computer and use it in GitHub Desktop.
Save rruntsch/36495ae585247fb88434ec92065f7f5b to your computer and use it in GitHub Desktop.
Select customer data from the SQL Server Adventure Works database to demonstrate saving returned data to a CSV file.
-- File: customer_location_csv.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 plain text format.
USE AdventureWorks2019;
GO
SELECT
-- TOP (5)
BusinessEntityID
, City
, StateProvinceName
, PostalCode
, CountryRegionName
FROM [AdventureWorks2019].[Sales].[vIndividualCustomer]
ORDER BY
CountryRegionName
, StateProvinceName
, City;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment