· 8 years ago · Dec 25, 2017, 02:38 PM
1--Updates the itemSubSubType
2if (@itemSubSubTypeId IS NOT NULL) --Only proceed if @itemSubSubTypeLinkId is not null
3BEGIN
4 --Checks if the table already exists
5 SET @i = (Select itemSubSubTypeLink.subSubTypeId FROM Items LEFT OUTER JOIN itemSubSubTypeLink on items.itemId = itemSubSubTypeLink.itemId WHERE Items.itemId = @itemId)
6 if (@i IS NOT NULL) --ie. table already exists, modify it
7 BEGIN
8 UPDATE itemSubSubTypeLink
9 SET itemId=@itemId, subSubTypeId=@itemSubSubTypeId
10 WHERE itemId =@itemId
11 END
12
13 ELSE --ie. table doesnt yet exist, create the table
14 BEGIN
15 INSERT INTO itemSubSubTypeLink(itemId,subSubTypeId)
16 VALUES (@itemId, @itemSubSubTypeId)
17 END
18END
19
20ELSE --This will only run if @itemSubSubTypeLinkId is null. What we must do here is to check if the item previously had a subSubType, and if so, delete it
21BEGIN
22 --Checks if the table previously existed
23 SET @i = (Select itemSubSubTypeLink.subSubTypeId FROM Items LEFT OUTER JOIN itemSubSubTypeLink on items.itemId = itemSubSubTypeLink.itemId WHERE Items.itemId = @itemId)
24 if (@i IS NOT NULL)
25 BEGIN
26 DELETE itemSubSubTypeLink
27 FROM Items INNER JOIN itemSubSubTypeLink on Items.itemId = itemSubSubTypeLink.itemId
28 WHERE Items.itemId = @itemId
29 END
30END