· 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 IF recordAlreadyExists = FALSE
34 THEN
35 #----------------------------------------------------------------#
36 # Begin procedure for if the record DOES NOT exist in our records #
37 #----------------------------------------------------------------#
38 IF recordNotes IS NULL AND sortNumber IS NULL
39 THEN
40 INSERT INTO tempRecordHolder (union_ID,union_Name) VALUES (recordID, recordName);
41 END IF;
42 #--------------------------------------------------------------#
43 # End procedure for if the record DOES NOT exist in our records #
44 #--------------------------------------------------------------#
45 ELSE
46 #-------------------------------------------------------------#
47 # Begin procedure for if the record DOES exist in our records #
48 #-------------------------------------------------------------#
49 IF recordAlreadyExists = TRUE
50 THEN
51 UPDATE tempRecordHolder SET union_Name = 'blah' WHERE union_ID=1234;
52 END IF;
53 END IF;
54 /*
55 #-----------------------------#
56 # Begin data processing setup #
57 #-----------------------------#
58
59 # Declare all the necessary variables for making a cursor
60 DECLARE finished BOOLEAN DEFAULT FALSE;
61 DECLARE colNameForInsert varChar(50);
62 DECLARE columnName CURSOR FOR
63 (
64 SELECT `COLUMN_NAME`
65 FROM `INFORMATION_SCHEMA`.`COLUMNS`
66 WHERE `TABLE_NAME`='tempRecordHolder';
67 );
68 DECLARE CONTINUE HANDLER
69 FOR NOT FOUND SET finished = TRUE;
70
71 #---------------------------#
72 # END data processing setup #
73 #---------------------------#
74
75 #--------------------------------#
76 # Begin main loop and processing #
77 #--------------------------------#
78
79 OPEN columnName;
80 manFunc: loop
81
82 # check to see if we are done before running the rest of the loop
83 IF finished = TRUE THEN
84 LEAVE mainFunc;
85 END IF;
86 FETCH columnName INTO colNameForInsert;
87
88 IF
89
90 END LOOP mainFunc;
91 CLOSE columnName;
92
93 #------------------------------#
94 # END main loop and processing #
95 #------------------------------#
96
97 */
98
99END