Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.81 KB | None | 0 0
  1. -- Add table with all partyIDS
  2. SELECT DISTINCT party_id
  3. INTO   #partyids
  4. FROM   tge_games
  5.  
  6. -- ADD table with all platform type
  7. SELECT DISTINCT platform_type
  8. INTO   #platform_type
  9. FROM   tge_games_operators
  10.  
  11. -- Create table with cross party id and platform type
  12. SELECT *
  13. INTO   #partandplat
  14. FROM   #platform_type
  15.        CROSS JOIN #partyids
  16.  
  17. -- data to be inserted for disable all party ids for all platform for list of operators
  18. SELECT *
  19. INTO   #fulltable
  20. FROM   (SELECT to_operators.operator_id AS OPERATOR_ID,
  21.                -1                       AS GAME_ID,
  22.                TP.*
  23.         FROM   to_operators,
  24.                (SELECT *
  25.                 FROM   #partandplat) AS TP
  26.         WHERE  operator_id IN ( 1, 2, 3, 12,
  27.                                 21, 20 )) AS TT
  28.  
  29. -- create a cursor to delete from TGE_Games operators if key already exists
  30. DECLARE @DeleteExistKeysCursors AS CURSOR
  31. DECLARE @Game_ID INT
  32. DECLARE @Operator_ID INT
  33. DECLARE @Party_ID INT
  34. DECLARE @Platform_Type NCHAR(10)
  35.  
  36. SET @DeleteExistKeysCursors = CURSOR
  37. FOR SELECT *
  38.     FROM   #fulltable
  39.  
  40. ---------------------
  41. OPEN @DeleteExistKeysCursors
  42.  
  43. FETCH next FROM @DeleteExistKeysCursors --Start the cursor
  44. INTO @Operator_ID, @Game_ID, @Platform_Type, @Party_ID
  45.  
  46. WHILE @@FETCH_STATUS = 0 --while there is a loaded record, keep processing
  47.   BEGIN
  48.       DELETE FROM tge_games_operators
  49.       WHERE  operator_id = @Operator_ID
  50.              AND game_id = @Game_ID
  51.              AND platform_type = @Platform_Type
  52.              AND @Party_ID = party_id
  53.  
  54.       FETCH next FROM @DeleteExistKeysCursors --Start the cursor
  55.       INTO @Operator_ID, @Game_ID, @Platform_Type, @Party_ID
  56.   END
  57.  
  58. CLOSE @DeleteExistKeysCursors
  59.  
  60. INSERT INTO tge_games_operators
  61. SELECT *
  62. FROM   #fulltable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement