1

I have this table with lot of parameters :

idPumpParam|Type   |Version|A10A|A11A|A12A|A13A|A14A|...

1          |Pump1  |DL cons|1   |32  |45  |6   |67  |...

2          |Pump2  |DL var |2   |65  |8   |37  |43  |...

For search the parameter with my automation, I would like to create a procedure in MySQL Workbench 5.7:

CREATE DEFINER = `root`@`localhost` 
PROCEDURE `procReadParam`(IN Param VARCHAR(20), 
                          IN TypePpe VARCHAR(20), 
                          IN Version VARCHAR(20))
BEGIN
    SELECT Param FROM pumpparameters.pumpparam 
    WHERE Type1 LIKE TypePpe AND Version=Version AND Frequence=Freq;
END

The procedure is good, no error message.

I test the procedure in MySQL Workbench:

call pumpparameters.procReadParam(A12A, 'Pump1', 'DL cons')

There are this error message:

Error Code: 1054. Unknown column 'A12A' in 'field list'

Can you help me for this error message please?

2 Answers 2

2

Have you tried calling the procedure with Param in single quotes? Like this: call pumpparameters.procReadParam('A12A', 'Pump1', 'DL cons')

Sign up to request clarification or add additional context in comments.

1 Comment

With ' ' the answer is : Param | A12A
1

If you want to use a column dynamically in a procedure, you can prepare and execute a SQL string statement

Something like this:

DELIMITER //
CREATE DEFINER = `root`@`localhost` 
PROCEDURE `procReadParam`(IN Param VARCHAR(20), 
                          IN TypePpe VARCHAR(20), 
                          IN Version VARCHAR(20))
BEGIN
  SET @sql = CONCAT('SELECT ', Param, ' FROM  pumpparameters.pumpparam WHERE Type1 = \'', TypePpe ,' AND Version =\'',Version,'\'');
  PREPARE stmt FROM @sql;
  EXECUTE stmt;
  DEALLOCATE PREPARE stmt;
END//
DELIMITER ;

Notes:

  • for your VARCHAR columns, you should surround their values with single quotes, and thus properly escape that in your CONCAT (with \')
  • I replaced the LIKE with = because a LIKE had no purpose there.
  • I removed the Freq part because you don't pass it as a parameter

So you have to make a few adaptations to make it working like you want

1 Comment

For the moment it's a test table, the real table will be very big. I need LIKE '%Pump1%' because instead of Pump1 there are many pump with the same parameters : Type | MN 0100B, MP 0100 B, MQ 0100 B... | NU 2000 N| BJ 0400 B, BG 1300 J.... . I need Freq because the same Pump can have a motor in 50 or 60 or 90Hz but with differents parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.