-
Notifications
You must be signed in to change notification settings - Fork 10
/
upgrade-product-groups-and-open-docs.sql
110 lines (98 loc) · 3.31 KB
/
upgrade-product-groups-and-open-docs.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
USE DynamicsNAV
GO
DECLARE @ProductGroupItemCategory TABLE
(
ItemCategory nvarchar(50) Collate Latin1_General_100_CI_AS NOT NULL,
ProductGroup nvarchar(50) Collate Latin1_General_100_CI_AS NOT NULL,
NewItemCategory nvarchar(50) Collate Latin1_General_100_CI_AS NOT NULL,
NewDescription nvarchar(50) Collate Latin1_General_100_CI_AS NOT NULL
)
INSERT INTO @ProductGroupItemCategory
( ItemCategory, ProductGroup, NewItemCategory, NewDescription)
SELECT pg.[Item Category Code], pg.Code, pg.[Item Category Code] + '-' + pg.Code, pg.[Description]
FROM [Cronus$Product Group] pg
WHERE pg.[Item Category Code] <> ''
INSERT INTO [Cronus$Item Category]
(Code, Description, [Parent Category]
,[Indentation],[Presentation Order],[Has Children],[Last Modified Date Time],[Id],[Manifest Signature Reqd_]
,[Web Id],[Web Guid],[Display Order],[Xml Package],[Published],[Show In Product Browser]
,[Column Width],[Page Size],[Skin Id],[Template Name],[Wholesale])
SELECT
NewItemCategory, NewDescription, ItemCategory
,0,0,0,'1753-01-01 00:00:00.000','00000000-0000-0000-0000-000000000000',0
,0,'',1,'',1,1
,0,0,0,'',0
FROM @ProductGroupItemCategory pgic
LEFT JOIN [Cronus$Item Category] ic
ON ic.Code = pgic.NewItemCategory
WHERE ic.Code IS NULL
UPDATE i
SET [Item Category Code] = NewItemCategory
FROM [Cronus$Item] i
INNER JOIN @ProductGroupItemCategory pgic
ON pgic.ItemCategory = i.[Item Category Code] AND pgic.ProductGroup = i.[Product Group Code]
WHERE i.[Item Category Code] <> NewItemCategory
-- Open Documents
PRINT 'Processing Sales Line'
GO
UPDATE t
SET [Item Category Code] = i.[Item Category Code]
FROM [dbo].[Cronus$Sales Line] t
INNER JOIN [dbo].[Cronus$Item] i (nolock)
ON i.No_ = t.No_
WHERE t.Type = 2 AND t.[Item Category Code] <> i.[Item Category Code]
GO
PRINT 'Processing Purchase Line'
GO
UPDATE t
SET [Item Category Code] = i.[Item Category Code]
FROM [dbo].[Cronus$Purchase Line] t
INNER JOIN [dbo].[Cronus$Item] i (nolock)
ON i.No_ = t.No_
WHERE t.Type = 2 AND t.[Item Category Code] <> i.[Item Category Code]
GO
PRINT 'Processing Transfer Line'
GO
UPDATE t
SET [Item Category Code] = i.[Item Category Code]
FROM [dbo].[Cronus$Transfer Line] t
INNER JOIN [dbo].[Cronus$Item] i (nolock)
ON i.No_ = t.[Item No_]
WHERE t.[Item Category Code] <> i.[Item Category Code]
GO
PRINT 'Processing Requisition Line'
GO
UPDATE t
SET [Item Category Code] = i.[Item Category Code]
FROM [dbo].[Cronus$Requisition Line] t
INNER JOIN [dbo].[Cronus$Item] i (nolock)
ON i.No_ = t.No_
WHERE t.Type = 2 AND t.[Item Category Code] <> i.[Item Category Code]
GO
PRINT 'Processing Service Line'
GO
UPDATE t
SET [Item Category Code] = i.[Item Category Code]
FROM [dbo].[Cronus$Service Line] t
INNER JOIN [dbo].[Cronus$Item] i (nolock)
ON i.No_ = t.No_
WHERE t.Type = 1 AND t.[Item Category Code] <> i.[Item Category Code]
GO
PRINT 'Processing Standard Item Journal Line'
GO
UPDATE t
SET [Item Category Code] = i.[Item Category Code]
FROM [dbo].[Cronus$Standard Item Journal Line] t
INNER JOIN [dbo].[Cronus$Item] i (nolock)
ON i.No_ = t.[Item No_]
WHERE t.[Item Category Code] <> i.[Item Category Code]
GO
PRINT 'Processing Item Journal Line'
GO
UPDATE t
SET [Item Category Code] = i.[Item Category Code]
FROM [dbo].[Cronus$Item Journal Line] t
INNER JOIN [dbo].[Cronus$Item] i (nolock)
ON i.No_ = t.[Item No_]
WHERE t.[Item Category Code] <> i.[Item Category Code]
GO