-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInventory Management Script.sql
229 lines (167 loc) · 6.58 KB
/
Inventory Management Script.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/****** Script for SelectTopNRows command from SSMS ******/
--SELECT * FROM [AdventureWorks2019].[Production].[ProductCategory] ---4 ROWS
--SELECT * FROM [AdventureWorks2019].[Production].[Product] --504 ROWS
--SELECT * FROM [AdventureWorks2019].[Production].[Location] --14 ROWS
--SELECT * FROM [AdventureWorks2019].[Production].[ProductSubcategory] ---37 ROWS
--SELECT * FROM [AdventureWorks2019].[Production].[ProductInventory] ---- 1069 rows
--select * from Production.ScrapReason ---16 rows
--select * from Production.WorkOrder -- 72591 rows
--select * from Production.WorkOrderRouting -- 67131 rows
--select * from Sales.SalesOrderDetail -- 121317 rows
--DROP VIEW IF EXISTS Production.Product_view;
--GO
--CREATE VIEW Production.Product_view AS
--SELECT [ProductID], [Name] as ProductName,[ProductNumber]
-- ,[MakeFlag], [FinishedGoodsFlag] as SellableProduct
-- ,[Color] as ProductColor, [SafetyStockLevel] as MinInvQty
-- ,[ReorderPoint] as Reorder, [StandardCost]
-- ,[ListPrice] as SellingCost, [Size] as ProductSize
-- ,[SizeUnitMeasureCode], [WeightUnitMeasureCode]
-- ,[Weight] as ProductWeight, [DaysToManufacture]
-- ,[ProductLine], [Class], [Style]
-- ,[ProductSubcategoryID],[ProductModelID]
-- ,[SellStartDate], [SellEndDate]
-- ,[DiscontinuedDate], [rowguid], [ModifiedDate]
-- ,CASE WHEN MakeFlag = '0' THEN 'Purchased'
-- ELSE 'Manufactured' END as ManufacturingPosition
-- ,CASE WHEN [FinishedGoodsFlag] = '0' THEN 'NotSellable'
-- ELSE 'Sellable' END as SellingPosition
-- ,CASE WHEN [ProductLine] = 'R' THEN 'Road'
-- WHEN [ProductLine] = 'M' THEN 'Mountain'
-- WHEN [ProductLine] = 'T' THEN 'Touring'
-- WHEN [ProductLine] = 'S' THEN 'Standard'
-- ELSE 'Null' END as ProductRoute
-- ,CASE WHEN [Class] = 'H' THEN 'High'
-- WHEN [Class] = 'M' THEN 'Medium'
-- WHEN [Class] = 'L' THEN 'Low'
-- ELSE 'Null' END as Classy
-- ,CASE WHEN [Style] = 'W' THEN 'Women'
-- WHEN [Style] = 'M' THEN 'Mens'
-- WHEN [Style] = 'U' THEN 'Universal'
-- ELSE 'Null' END as Stylish
-- FROM [AdventureWorks2019].[Production].[Product]
--------------------------------------------------------------------------------------
-- DROP VIEW IF EXISTS Production.Location_view;
--GO
--CREATE VIEW Production.Location_view AS
-- SELECT [LocationID]
-- ,[Name] as LocationDescription
-- ,[CostRate]
-- ,[Availability] as WorkCapacity_Hr
-- ,[ModifiedDate]
-- FROM [AdventureWorks2019].[Production].[Location]
--------------------------------------------------------------------------------------
--DROP VIEW IF EXISTS Production.ProductCategory_view;
--GO
--CREATE VIEW Production.ProductCategory_view AS
--SELECT [ProductCategoryID]
-- ,[Name] as CategoryDescription
-- ,[rowguid]
-- ,[ModifiedDate]
-- FROM [AdventureWorks2019].[Production].[ProductCategory]
--------------------------------------------------------------------------------------
-- DROP VIEW IF EXISTS Production.ProductSubcategory_view;
--GO
--CREATE VIEW Production.ProductSubcategory_view AS
-- SELECT [ProductSubcategoryID]
-- ,[ProductCategoryID]
-- ,[Name] as SubCategoryDescription
-- ,[rowguid]
-- ,[ModifiedDate]
-- FROM [AdventureWorks2019].[Production].[ProductSubcategory]
--------------------------------------------------------------------------------------
--DROP VIEW IF EXISTS Production.ProductInventory_view;
--GO
--CREATE VIEW Production.ProductInventory_view AS
--SELECT [ProductID]
-- ,[LocationID]
-- ,[Shelf] as StorageCompartment
-- ,[Bin] as StorageContainer
-- ,[Quantity]
-- ,[rowguid]
-- ,[ModifiedDate]
-- FROM [AdventureWorks2019].[Production].[ProductInventory]
-- --------------------------------------------------------------------------------------
--DROP VIEW IF EXISTS Production.ScrapReason_view;
--GO
--CREATE VIEW Production.ScrapReason_view AS
--SELECT [ScrapReasonID]
-- ,[Name] as FailureDescription
-- ,[ModifiedDate]
-- FROM [AdventureWorks2019].[Production].[ScrapReason]
-- --------------------------------------------------------------------------------------
--DROP VIEW IF EXISTS Production.WorkOrder_view;
--GO
--CREATE VIEW Production.WorkOrder_view AS
--SELECT [WorkOrderID]
-- ,[ProductID]
-- ,[OrderQty]
-- ,[StockedQty]
-- ,[ScrappedQty]
-- ,[StartDate]
-- ,[EndDate]
-- ,[DueDate]
-- ,[ScrapReasonID]
-- ,[ModifiedDate]
-- FROM [AdventureWorks2019].[Production].[WorkOrder]
-- --------------------------------------------------------------------------------------
--DROP VIEW IF EXISTS Production.WorkOrderRouting_view;
--GO
--CREATE VIEW Production.WorkOrderRouting_view AS
--SELECT [WorkOrderID]
-- ,[ProductID]
-- ,[OperationSequence]
-- ,[LocationID]
-- ,[ScheduledStartDate]
-- ,[ScheduledEndDate]
-- ,[ActualStartDate]
-- ,[ActualEndDate]
-- ,[ActualResourceHrs]
-- ,[PlannedCost]
-- ,[ActualCost]
-- ,[ModifiedDate]
-- FROM [AdventureWorks2019].[Production].[WorkOrderRouting]
-- --------------------------------------------------------------------------------------
--DROP VIEW IF EXISTS Sales.SalesOrderDetails_view;
--GO
--CREATE VIEW Sales.SalesOrderDetail_view AS
--SELECT [SalesOrderID]
-- ,[SalesOrderDetailID]
-- ,[CarrierTrackingNumber]
-- ,[OrderQty]
-- ,[ProductID]
-- ,[SpecialOfferID]
-- ,[UnitPrice]
-- ,[UnitPriceDiscount]
-- ,[LineTotal]
-- ,[rowguid]
-- ,[ModifiedDate]
-- FROM [AdventureWorks2019].[Sales].[SalesOrderDetail]
---------------------------------------------------------------------------------
DROP VIEW IF EXISTS Sales.SalesOrderHeader_view;
GO
CREATE VIEW Sales.SalesOrderHeader_view AS
SELECT [SalesOrderID]
,[RevisionNumber], [OrderDate]
,[DueDate], [ShipDate], [Status]
,[OnlineOrderFlag]
,[SalesOrderNumber]
,[PurchaseOrderNumber]
,[AccountNumber]
,[CustomerID]
,[SalesPersonID]
,[TerritoryID]
,[BillToAddressID]
,[ShipToAddressID]
,[ShipMethodID]
,[CreditCardID]
,[CreditCardApprovalCode]
,[CurrencyRateID]
,[SubTotal]
,[TaxAmt]
,[Freight]
,[TotalDue]
,[Comment]
,[rowguid]
,[ModifiedDate]
FROM [AdventureWorks2019].[Sales].[SalesOrderHeader]