MySQL Forums :: Stored Procedures :: Simply stored proc works OK but is it correct syntax ?


Advanced Search

Re: Simply stored proc works OK but is it correct syntax ?
Posted by: Russel James ()
Date: September 17, 2016 02:36PM

CrewID is a string. But that is really the question. I could not get it to work without the quotes.

Say the crewID was "AB01". I was getting error message 'column "AB01" does not exist'. Once I put the quotes around it in the SET statement, it began to work. I just wasnt sure if there was a better way of doing it.

Looking at the slightly longer query which includes a decimal value (wages)..

SET @crewID = CONCAT('"', p_crewID, '"');
SET @reference = CONCAT('"', p_reference, '"');
SET @wages = CONCAT('"', p_wages, '"'); // decimal value.



SET @s = CONCAT("INSERT INTO ", @wagesYear, "(crewID, reference, wages) VALUES (", @crewID, ",", @reference, ",", @wages, ")");
PREPARE stmt FROM @s;
EXECUTE stmt;

The above sql works as expected but seems quite long winded to me. Perhaps there is a way of bypassing the SET statements altogether and use the parameters (p_values) within the CONCAT statement ??

J

Options: ReplyQuote


Subject Views Written By Posted
Simply stored proc works OK but is it correct syntax ? 2495 Russel James 09/17/2016 12:17PM
Re: Simply stored proc works OK but is it correct syntax ? 237 Peter Brawley 09/17/2016 01:12PM
Re: Simply stored proc works OK but is it correct syntax ? 277 Russel James 09/17/2016 02:36PM
Re: Simply stored proc works OK but is it correct syntax ? 262 Peter Brawley 09/17/2016 04:32PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.