-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSalesItemsCsvImport.sql
More file actions
50 lines (47 loc) · 1.02 KB
/
Copy pathSalesItemsCsvImport.sql
File metadata and controls
50 lines (47 loc) · 1.02 KB
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
CREATE TABLE #TempTable
(
Region NVARCHAR(MAX) NULL,
Country NVARCHAR(MAX) NULL,
ItemType NVARCHAR(MAX) NULL,
SalesChannel NVARCHAR(MAX) NULL,
OrderPriority NVARCHAR(MAX) NULL,
OrderDate DATETIME NULL,
OrderId INT NULL,
ShipDate DATETIME NULL,
UnitSold BIGINT NULL,
UnitPrice MONEY NULL,
UnitCost MONEY NULL,
TotalRevenue MONEY NULL,
TotalCost MONEY NULL,
TotalProfit MONEY NULL
)
BULK INSERT #TempTable
FROM 'C:\100 Sales Records.csv'
WITH
(
CODEPAGE = 'ACP',
FIRSTROW = 2,
DATAFILETYPE='widechar',
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n',
TABLOCK,
KEEPNULLS
)
INSERT INTO dbo.Sales (Region, Country, ItemType, Channel, OrderPriority, OrderData, OrderId, ShipDate, UnitSold, UnitPrice, UnitCost, TotalRevenue, TotalCost, TotalProfit)
SELECT
csv.Region,
csv.Country,
csv.ItemType,
csv.SalesChannel,
csv.OrderPriority,
csv.OrderDate,
csv.OrderId,
csv.ShipDate,
csv.UnitSold,
csv.UnitPrice,
csv.UnitCost,
csv.TotalRevenue,
csv.TotalCost,
csv.TotalProfit
FROM #TempTable csv
DROP TABLE #TempTable