Integration.GetSaleUpdates
Documentation | WideWorldImporters |
Schema | Integration |
Name | GetSaleUpdates |
Helper procedures for the ETL package
Input/Output
Mode | Name | Data type | Description | |
---|---|---|---|---|
1 | IN | LastCutoff | datetime2(7) | |
2 | IN | NewCutoff | datetime2(7) |
Script
CREATE PROCEDURE Integration.GetSaleUpdates @LastCutoff datetime2(7), @NewCutoff datetime2(7) WITH EXECUTE AS OWNER AS BEGIN SET NOCOUNT ON; SET XACT_ABORT ON; SELECT CAST(i.InvoiceDate AS date) AS [Invoice Date Key], CAST(i.ConfirmedDeliveryTime AS date) AS [Delivery Date Key], i.InvoiceID AS [WWI Invoice ID], il.[Description], pt.PackageTypeName AS Package, il.Quantity, il.UnitPrice AS [Unit Price], il.TaxRate AS [Tax Rate], il.ExtendedPrice - il.TaxAmount AS [Total Excluding Tax], il.TaxAmount AS [Tax Amount], il.LineProfit AS Profit, il.ExtendedPrice AS [Total Including Tax], CASE WHEN si.IsChillerStock = 0 THEN il.Quantity ELSE 0 END AS [Total Dry Items], CASE WHEN si.IsChillerStock <> 0 THEN il.Quantity ELSE 0 END AS [Total Chiller Items], c.DeliveryCityID AS [WWI City ID], i.CustomerID AS [WWI Customer ID], i.BillToCustomerID AS [WWI Bill To Customer ID], il.StockItemID AS [WWI Stock Item ID], i.SalespersonPersonID AS [WWI Saleperson ID], CASE WHEN il.LastEditedWhen > i.LastEditedWhen THEN il.LastEditedWhen ELSE i.LastEditedWhen END AS [Last Modified When] FROM Sales.Invoices AS i INNER JOIN Sales.InvoiceLines AS il ON i.InvoiceID = il.InvoiceID INNER JOIN Warehouse.StockItems AS si ON il.StockItemID = si.StockItemID INNER JOIN Warehouse.PackageTypes AS pt ON il.PackageTypeID = pt.PackageTypeID INNER JOIN Sales.Customers AS c ON i.CustomerID = c.CustomerID INNER JOIN Sales.Customers AS bt ON i.BillToCustomerID = bt.CustomerID WHERE CASE WHEN il.LastEditedWhen > i.LastEditedWhen THEN il.LastEditedWhen ELSE i.LastEditedWhen END > @LastCutoff AND CASE WHEN il.LastEditedWhen > i.LastEditedWhen THEN il.LastEditedWhen ELSE i.LastEditedWhen END <= @NewCutoff ORDER BY i.InvoiceID, il.InvoiceLineID; RETURN 0; END; |
Exported: 2019-02-04 23:04, Last imported: 2018-08-10 09:51