· 9 years ago · Dec 28, 2016, 03:02 PM
1CREATE 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)
10BEGIN
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=null AND sortNumber=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 END IF;
64 /*
65 #-----------------------------#
66 # Begin data processing setup #
67 #-----------------------------#
68
69 # Declare all the necessary variables for making a cursor
70 DECLARE finished BOOLEAN DEFAULT FALSE;
71 DECLARE colNameForInsert varChar(50);
72 DECLARE columnName CURSOR FOR
73 (
74 SELECT `COLUMN_NAME`
75 FROM `INFORMATION_SCHEMA`.`COLUMNS`
76 WHERE `TABLE_NAME`='tempRecordHolder';
77 );
78 DECLARE CONTINUE HANDLER
79 FOR NOT FOUND SET finished = TRUE;
80
81 #---------------------------#
82 # END data processing setup #
83 #---------------------------#
84
85 #--------------------------------#
86 # Begin main loop and processing #
87 #--------------------------------#
88
89 OPEN columnName;
90 manFunc: loop
91
92 # check to see if we are done before running the rest of the loop
93 IF finished = TRUE THEN
94 LEAVE mainFunc;
95 END IF;
96 FETCH columnName INTO colNameForInsert;
97
98 IF
99
100 END LOOP mainFunc;
101 CLOSE columnName;
102
103 #------------------------------#
104 # END main loop and processing #
105 #------------------------------#
106
107 */
108
109END