Skip to content

Commit 80080aa

Browse files
Merge pull request microsoft#350 from JocaPC/master
Updated WWI Website views
2 parents 5dca06b + 0f25499 commit 80080aa

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/Website/Views/Customers.sql

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ SELECT s.CustomerID,
88
ap.FullName AS AlternateContact,
99
s.PhoneNumber,
1010
s.FaxNumber,
11-
bg.BuyingGroupName,
1211
s.WebsiteURL,
13-
dm.DeliveryMethodName AS DeliveryMethod,
14-
c.CityName AS CityName,
15-
s.DeliveryLocation AS DeliveryLocation,
16-
s.DeliveryRun,
17-
s.RunPosition
12+
bg.BuyingGroupName,
13+
DeliveryLocation = JSON_QUERY((SELECT
14+
type = 'Feature',
15+
[geometry.type] = 'Point',
16+
[geometry.coordinates] = JSON_QUERY(CONCAT('[',s.DeliveryLocation.Long,',',s.DeliveryLocation.Lat ,']')),
17+
[properties.DeliveryMethod] = DeliveryMethodName,
18+
[properties.CityName] = c.CityName,
19+
[properties.Province] = sp.StateProvinceName,
20+
[properties.Territory] = sp.SalesTerritory
21+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER))
1822
FROM Sales.Customers AS s
1923
LEFT OUTER JOIN Sales.CustomerCategories AS sc
2024
ON s.CustomerCategoryID = sc.CustomerCategoryID
@@ -28,3 +32,5 @@ LEFT OUTER JOIN [Application].DeliveryMethods AS dm
2832
ON s.DeliveryMethodID = dm.DeliveryMethodID
2933
LEFT OUTER JOIN [Application].Cities AS c
3034
ON s.DeliveryCityID = c.CityID
35+
LEFT OUTER JOIN [Application].StateProvinces AS sp
36+
ON sp.StateProvinceID = c.StateProvinceID
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11

22
CREATE VIEW Website.SalesOrders
33
AS
4-
SELECT o.OrderID, o.OrderDate, OrderNumber = o.CustomerPurchaseOrderNumber, o.ExpectedDeliveryDate,
5-
o.PickingCompletedWhen, o.DeliveryInstructions,
4+
SELECT o.OrderID, o.OrderDate, OrderNumber = o.CustomerPurchaseOrderNumber,
5+
o.ExpectedDeliveryDate, o.PickingCompletedWhen,
66
o.CustomerID, c.CustomerName, c.PhoneNumber, c.FaxNumber, c.WebsiteURL,
7-
c.DeliveryAddressLine1, c.DeliveryAddressLine2, c.DeliveryPostalCode, c.DeliveryLocation,
7+
DeliveryLocation = JSON_QUERY((SELECT
8+
[type] = 'Feature',
9+
[geometry.type] = 'Point',
10+
[geometry.coordinates] = JSON_QUERY(CONCAT('[',c.DeliveryLocation.Long,',',c.DeliveryLocation.Lat ,']')),
11+
[properties.DeliveryMethod] = dm.DeliveryMethodName,
12+
[properties.AddressLine1] = c.DeliveryAddressLine1,
13+
[properties.AddressLine2] = c.DeliveryAddressLine2,
14+
[properties.PostalCode] = c.DeliveryPostalCode,
15+
[properties.Instructions] = o.DeliveryInstructions
16+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER)),
817
SalesPerson = sp.FullName, SalesPersonPhone = sp.PhoneNumber, SalesPersonEmail = sp.EmailAddress
918
FROM Sales.Orders o
1019
INNER JOIN Sales.Customers c
1120
ON o.CustomerID = c.CustomerID
21+
LEFT OUTER JOIN [Application].DeliveryMethods AS dm
22+
ON c.DeliveryMethodID = dm.DeliveryMethodID
1223
INNER JOIN Application.People sp
1324
ON o.SalespersonPersonID = sp.PersonID
14-
25+

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/Website/Views/Suppliers.sql

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,26 @@ SELECT s.SupplierID,
99
s.PhoneNumber,
1010
s.FaxNumber,
1111
s.WebsiteURL,
12-
dm.DeliveryMethodName AS DeliveryMethod,
13-
c.CityName AS CityName,
14-
s.DeliveryLocation AS DeliveryLocation,
15-
s.SupplierReference
12+
s.SupplierReference,
13+
DeliveryLocation = JSON_QUERY((SELECT
14+
[type] = 'Feature',
15+
[geometry.type] = 'Point',
16+
[geometry.coordinates] = JSON_QUERY(CONCAT('[',s.DeliveryLocation.Long,',',s.DeliveryLocation.Lat ,']')),
17+
[properties.DeliveryMethod] = dm.DeliveryMethodName,
18+
[properties.City] = c.CityName,
19+
[properties.Province] = sp.StateProvinceName,
20+
[properties.Territory] = sp.SalesTerritory
21+
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER))
1622
FROM Purchasing.Suppliers AS s
17-
LEFT OUTER JOIN Purchasing.SupplierCategories AS sc
18-
ON s.SupplierCategoryID = sc.SupplierCategoryID
19-
LEFT OUTER JOIN [Application].People AS pp
20-
ON s.PrimaryContactPersonID = pp.PersonID
21-
LEFT OUTER JOIN [Application].People AS ap
22-
ON s.AlternateContactPersonID = ap.PersonID
23-
LEFT OUTER JOIN [Application].DeliveryMethods AS dm
24-
ON s.DeliveryMethodID = dm.DeliveryMethodID
25-
LEFT OUTER JOIN [Application].Cities AS c
26-
ON s.DeliveryCityID = c.CityID
23+
LEFT OUTER JOIN Purchasing.SupplierCategories AS sc
24+
ON s.SupplierCategoryID = sc.SupplierCategoryID
25+
LEFT OUTER JOIN [Application].People AS pp
26+
ON s.PrimaryContactPersonID = pp.PersonID
27+
LEFT OUTER JOIN [Application].People AS ap
28+
ON s.AlternateContactPersonID = ap.PersonID
29+
LEFT OUTER JOIN [Application].DeliveryMethods AS dm
30+
ON s.DeliveryMethodID = dm.DeliveryMethodID
31+
LEFT OUTER JOIN [Application].Cities AS c
32+
ON s.DeliveryCityID = c.CityID
33+
LEFT OUTER JOIN [Application].StateProvinces AS sp
34+
ON sp.StateProvinceID = c.StateProvinceID

0 commit comments

Comments
 (0)