Advertisement
andrefecto

SP

Dec 28th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.71 KB | None | 0 0
  1. CREATE DEFINER=`apf15102`@`%` PROCEDURE `sp_cu_LookUpTbls`(
  2.     IN tbl_Name varchar(50),
  3.     recordID int,
  4.     recordName varChar(500),
  5.     # REMEMBER THERE IS A DATE BETWEEN THESE TWO FIELDS IN THE TABLE STRUCTURES
  6.     recordNotes longtext,
  7.     sortNumber int,
  8.     recordAlreadyExists bit
  9. )
  10. BEGIN
  11.    
  12.     #-------------------------------#
  13.     # Begin preliminary table setup #
  14.     #-------------------------------#
  15.    
  16.     # Begin by dropping my temp table
  17.     DROP TEMPORARY TABLE IF EXISTS tempRecordHolder;
  18.    
  19.     # set my session variable equal to my passed in table name
  20.     SET @tblName = tbl_Name;
  21.    
  22.     # create a session variable string that is the create table for the table that was passed in
  23.     SET @tbl_Create_Command = concat("CREATE TEMPORARY TABLE tempRecordHolder LIKE " , @tblName);
  24.    
  25.     # prepare the statement making it one string that can be executed then execute it
  26.     prepare stmtCreate FROM @tbl_Create_Command;
  27.     execute stmtCreate;
  28.    
  29.     #-----------------------------#
  30.     # End preliminary table setup #
  31.     #-----------------------------#
  32.    
  33.    
  34.     # This code right here gives a "Syntax Error: Unexpected WHEN (when)" if it is un-commented
  35.     /*
  36.     CASE
  37.         WHEN recordNotes IS NULL AND sortNumber IS NULL
  38.             THEN INSERT INTO tempRecordHolder (union_ID,union_Name) VALUES (recordID, recordName);
  39.         ELSE SET @blank="null";
  40.     END CASE;
  41.     */
  42.    
  43.     IF recordAlreadyExists = FALSE
  44.         THEN
  45.             #-----------------------------------------------------------------#
  46.             # Begin procedure for if the record DOES NOT exist in our records #
  47.             #-----------------------------------------------------------------#
  48.             IF recordNotes IS NULL AND sortNumber IS NULL
  49.                 THEN
  50.                     INSERT INTO tempRecordHolder (union_ID,union_Name) VALUES (recordID, recordName);
  51.             END IF;
  52.             #---------------------------------------------------------------#
  53.             # End procedure for if the record DOES NOT exist in our records #
  54.             #---------------------------------------------------------------#
  55.         ELSE  
  56.             #-------------------------------------------------------------#
  57.             # Begin procedure for if the record DOES exist in our records #
  58.             #-------------------------------------------------------------#
  59.             IF recordAlreadyExists = TRUE
  60.                 THEN
  61.                     UPDATE tempRecordHolder SET union_Name = 'blah' WHERE union_ID=1234;
  62.             END IF;
  63.             #-----------------------------------------------------------#
  64.             # END procedure for if the record DOES exist in our records #
  65.             #-----------------------------------------------------------#
  66.     END IF;
  67.     /*
  68.     #-----------------------------#
  69.     # Begin data processing setup #
  70.     #-----------------------------#
  71.    
  72.     # Declare all the necessary variables for making a cursor
  73.     DECLARE finished BOOLEAN DEFAULT FALSE;
  74.     DECLARE colNameForInsert varChar(50);
  75.     DECLARE columnName CURSOR FOR
  76.         (
  77.             SELECT `COLUMN_NAME`
  78.             FROM `INFORMATION_SCHEMA`.`COLUMNS`
  79.             WHERE `TABLE_NAME`='tempRecordHolder';
  80.         );
  81.     DECLARE CONTINUE HANDLER
  82.         FOR NOT FOUND SET finished = TRUE;
  83.        
  84.     #---------------------------#
  85.     # END data processing setup #
  86.     #---------------------------#
  87.    
  88.     #--------------------------------#
  89.     # Begin main loop and processing #
  90.     #--------------------------------#
  91.    
  92.     OPEN columnName;
  93.     manFunc: loop
  94.    
  95.         # check to see if we are done before running the rest of the loop
  96.         IF finished = TRUE THEN
  97.             LEAVE mainFunc;
  98.         END IF;
  99.         FETCH columnName INTO colNameForInsert;
  100.        
  101.         IF
  102.    
  103.     END LOOP mainFunc;
  104.     CLOSE columnName;
  105.    
  106.     #------------------------------#
  107.     # END main loop and processing #
  108.     #------------------------------#
  109.    
  110.     */
  111.    
  112. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement