Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE DEFINER=`apf15102`@`%` PROCEDURE `sp_cu_LookUpTbls`(
- IN tbl_Name varchar(50),
- recordID int,
- recordName varChar(500),
- # REMEMBER THERE IS A DATE BETWEEN THESE TWO FIELDS IN THE TABLE STRUCTURES
- recordNotes longtext,
- sortNumber int,
- recordAlreadyExists bit
- )
- BEGIN
- #-------------------------------#
- # Begin preliminary table setup #
- #-------------------------------#
- # Begin by dropping my temp table
- DROP TEMPORARY TABLE IF EXISTS tempRecordHolder;
- # set my session variable equal to my passed in table name
- SET @tblName = tbl_Name;
- # create a session variable string that is the create table for the table that was passed in
- SET @tbl_Create_Command = concat("CREATE TEMPORARY TABLE tempRecordHolder LIKE " , @tblName);
- # prepare the statement making it one string that can be executed then execute it
- prepare stmtCreate FROM @tbl_Create_Command;
- execute stmtCreate;
- #-----------------------------#
- # End preliminary table setup #
- #-----------------------------#
- # This code right here gives a "Syntax Error: Unexpected WHEN (when)" if it is un-commented
- /*
- CASE
- WHEN recordNotes IS NULL AND sortNumber IS NULL
- THEN INSERT INTO tempRecordHolder (union_ID,union_Name) VALUES (recordID, recordName);
- ELSE SET @blank="null";
- END CASE;
- */
- IF recordAlreadyExists = FALSE
- THEN
- #-----------------------------------------------------------------#
- # Begin procedure for if the record DOES NOT exist in our records #
- #-----------------------------------------------------------------#
- IF recordNotes IS NULL AND sortNumber IS NULL
- THEN
- INSERT INTO tempRecordHolder (union_ID,union_Name) VALUES (recordID, recordName);
- END IF;
- #---------------------------------------------------------------#
- # End procedure for if the record DOES NOT exist in our records #
- #---------------------------------------------------------------#
- ELSE
- #-------------------------------------------------------------#
- # Begin procedure for if the record DOES exist in our records #
- #-------------------------------------------------------------#
- IF recordAlreadyExists = TRUE
- THEN
- UPDATE tempRecordHolder SET union_Name = 'blah' WHERE union_ID=1234;
- END IF;
- #-----------------------------------------------------------#
- # END procedure for if the record DOES exist in our records #
- #-----------------------------------------------------------#
- END IF;
- /*
- #-----------------------------#
- # Begin data processing setup #
- #-----------------------------#
- # Declare all the necessary variables for making a cursor
- DECLARE finished BOOLEAN DEFAULT FALSE;
- DECLARE colNameForInsert varChar(50);
- DECLARE columnName CURSOR FOR
- (
- SELECT `COLUMN_NAME`
- FROM `INFORMATION_SCHEMA`.`COLUMNS`
- WHERE `TABLE_NAME`='tempRecordHolder';
- );
- DECLARE CONTINUE HANDLER
- FOR NOT FOUND SET finished = TRUE;
- #---------------------------#
- # END data processing setup #
- #---------------------------#
- #--------------------------------#
- # Begin main loop and processing #
- #--------------------------------#
- OPEN columnName;
- manFunc: loop
- # check to see if we are done before running the rest of the loop
- IF finished = TRUE THEN
- LEAVE mainFunc;
- END IF;
- FETCH columnName INTO colNameForInsert;
- IF
- END LOOP mainFunc;
- CLOSE columnName;
- #------------------------------#
- # END main loop and processing #
- #------------------------------#
- */
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement