Skip to content

Commit 20a3393

Browse files
committed
Handled NULL columns and some missing columns in views.
1 parent b8de616 commit 20a3393

6 files changed

Lines changed: 18 additions & 16 deletions

File tree

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/WebApi/Stored Procedures/UpdateCustomerTransactionFromJson.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ AS BEGIN
44
SET QUOTED_IDENTIFIER ON;
55
UPDATE Sales.CustomerTransactions SET
66
TransactionTypeID = ISNULL(json.TransactionTypeID, Sales.CustomerTransactions.TransactionTypeID),
7-
PaymentMethodID = ISNULL(json.PaymentMethodID, Sales.CustomerTransactions.PaymentMethodID),
7+
PaymentMethodID = json.PaymentMethodID,
88
TransactionDate = ISNULL(json.TransactionDate, Sales.CustomerTransactions.TransactionDate),
99
AmountExcludingTax = ISNULL(json.AmountExcludingTax, Sales.CustomerTransactions.AmountExcludingTax),
1010
TaxAmount = ISNULL(json.TaxAmount, Sales.CustomerTransactions.TaxAmount),
1111
TransactionAmount = ISNULL(json.TransactionAmount, Sales.CustomerTransactions.TransactionAmount),
1212
OutstandingBalance = ISNULL(json.OutstandingBalance, Sales.CustomerTransactions.OutstandingBalance),
13-
FinalizationDate = ISNULL(json.FinalizationDate, Sales.CustomerTransactions.FinalizationDate),
13+
FinalizationDate = json.FinalizationDate,
1414
LastEditedBy = @UserID
1515
FROM OPENJSON(@CustomerTransaction)
1616
WITH (

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/WebApi/Stored Procedures/UpdatePurchaseOrderFromJson.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
CREATE PROCEDURE [WebApi].[UpdatePurchaseOrderFromJson](@PurchaseOrder NVARCHAR(MAX), @PurchaseOrderID int, @UserID int)
22
WITH EXECUTE AS OWNER
33
AS BEGIN UPDATE Purchasing.PurchaseOrders SET
4-
SupplierID = ISNULL(json.SupplierID,Purchasing.PurchaseOrders.SupplierID),
4+
SupplierID = json.SupplierID,
55
OrderDate = ISNULL(json.OrderDate,Purchasing.PurchaseOrders.OrderDate),
66
DeliveryMethodID = ISNULL(json.DeliveryMethodID,Purchasing.PurchaseOrders.DeliveryMethodID),
77
ContactPersonID = ISNULL(json.ContactPersonID,Purchasing.PurchaseOrders.ContactPersonID),
8-
ExpectedDeliveryDate = ISNULL(json.ExpectedDeliveryDate,Purchasing.PurchaseOrders.ExpectedDeliveryDate),
9-
SupplierReference = ISNULL(json.SupplierReference,Purchasing.PurchaseOrders.SupplierReference),
8+
ExpectedDeliveryDate = json.ExpectedDeliveryDate,
9+
SupplierReference = json.SupplierReference,
1010
IsOrderFinalized = ISNULL(json.IsOrderFinalized,Purchasing.PurchaseOrders.IsOrderFinalized)
1111
FROM OPENJSON(@PurchaseOrder)
1212
WITH (

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/WebApi/Stored Procedures/UpdateSpecialDealFromJson.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
CREATE PROCEDURE [WebApi].[UpdateSpecialDealFromJson](@SpecialDeal NVARCHAR(MAX), @SpecialDealID int, @UserID int)
22
WITH EXECUTE AS OWNER
33
AS BEGIN UPDATE Sales.SpecialDeals SET
4-
StockItemID = ISNULL(json.StockItemID,Sales.SpecialDeals.StockItemID),
5-
CustomerID = ISNULL(json.CustomerID,Sales.SpecialDeals.CustomerID),
6-
BuyingGroupID = ISNULL(json.BuyingGroupID,Sales.SpecialDeals.BuyingGroupID),
7-
CustomerCategoryID = ISNULL(json.CustomerCategoryID,Sales.SpecialDeals.CustomerCategoryID),
8-
StockGroupID = ISNULL(json.StockGroupID,Sales.SpecialDeals.StockGroupID),
4+
StockItemID = json.StockItemID,
5+
CustomerID = json.CustomerID,
6+
BuyingGroupID = json.BuyingGroupID,
7+
CustomerCategoryID = json.CustomerCategoryID,
8+
StockGroupID = json.StockGroupID,
99
DealDescription = ISNULL(json.DealDescription,Sales.SpecialDeals.DealDescription),
1010
StartDate = ISNULL(json.StartDate,Sales.SpecialDeals.StartDate),
1111
EndDate = ISNULL(json.EndDate,Sales.SpecialDeals.EndDate),
12-
DiscountAmount = ISNULL(json.DiscountAmount,Sales.SpecialDeals.DiscountAmount),
13-
DiscountPercentage = ISNULL(json.DiscountPercentage,Sales.SpecialDeals.DiscountPercentage),
14-
UnitPrice = ISNULL(json.UnitPrice,Sales.SpecialDeals.UnitPrice),
12+
DiscountAmount = json.DiscountAmount,
13+
DiscountPercentage = json.DiscountPercentage,
14+
UnitPrice = json.UnitPrice,
1515
LastEditedBy = @UserID
1616
FROM OPENJSON(@SpecialDeal)
1717
WITH (

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/WebApi/Stored Procedures/UpdateSupplierTransactionFromJson.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ AS BEGIN
55
UPDATE Purchasing.SupplierTransactions SET
66
SupplierID = ISNULL(json.SupplierID,Purchasing.SupplierTransactions.SupplierID),
77
TransactionTypeID = ISNULL(json.TransactionTypeID,Purchasing.SupplierTransactions.TransactionTypeID),
8-
PurchaseOrderID = ISNULL(json.PurchaseOrderID,Purchasing.SupplierTransactions.PurchaseOrderID),
9-
PaymentMethodID = ISNULL(json.PaymentMethodID,Purchasing.SupplierTransactions.PaymentMethodID),
8+
PurchaseOrderID = json.PurchaseOrderID,
9+
PaymentMethodID = json.PaymentMethodID,
1010
SupplierInvoiceNumber = ISNULL(json.SupplierInvoiceNumber,Purchasing.SupplierTransactions.SupplierInvoiceNumber),
1111
TransactionDate = ISNULL(json.TransactionDate,Purchasing.SupplierTransactions.TransactionDate),
1212
AmountExcludingTax = ISNULL(json.AmountExcludingTax,Purchasing.SupplierTransactions.AmountExcludingTax),

samples/databases/wide-world-importers/wwi-ssdt/wwi-ssdt/WebApi/Views/PurchaseOrders.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CREATE VIEW [WebApi].[PurchaseOrders]
22
AS
33
SELECT o.PurchaseOrderID, o.OrderDate, o.ExpectedDeliveryDate, o.SupplierReference, o.IsOrderFinalized,
4-
dm.DeliveryMethodName, o.SupplierID,
4+
dm.DeliveryMethodName, o.DeliveryMethodID, o.SupplierID,
55
ContactName = c.FullName, ContactPhone = c.PhoneNumber, ContactFax = c.FaxNumber, ContactEmail = c.EmailAddress
66
FROM Purchasing.PurchaseOrders o
77
INNER JOIN Application.People c

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ SELECT s.SupplierID,
1818
s.PostalAddressLine2,
1919
s.PostalPostalCode,
2020
s.PaymentDays,
21+
s.SupplierCategoryID,
2122
DeliveryLocation = JSON_QUERY((SELECT
2223
[type] = 'Feature',
2324
[geometry.type] = 'Point',
2425
[geometry.coordinates] = JSON_QUERY(CONCAT('[',s.DeliveryLocation.Long,',',s.DeliveryLocation.Lat ,']')),
2526
[properties.DeliveryMethod] = dm.DeliveryMethodName,
27+
[properties.DeliveryMethodID] = s.DeliveryMethodID,
2628
[properties.City] = c.CityName,
2729
[properties.Province] = sp.StateProvinceName,
2830
[properties.Territory] = sp.SalesTerritory

0 commit comments

Comments
 (0)