Problem with Store Procedure. It doesn´t update :(

Discussion in 'Databases' started by labonica_labonica, Jan 27, 2015.

  1. #1
    Hello!
    I need to update a field in a table with the total number of occurrences of the table B
    When I run the command below, it works.

    SELECT COUNT(P.cod_patient) FROM HOSP.PATIENT AS P

    When I put in the structure below, it does not error, but does not update the field. What might be happening?

    BEGIN

    DECLARE total_pacient INT;
    SET total_pacient = (SELECT COUNT(P.cod_pacient) FROM HOSP.PATIENT AS P);
    UPDATE
    HOSP.ESTATISTIC
    SET
    total_patient_bd = total_patient;
    END

    Thank you very much :)
     
    labonica_labonica, Jan 27, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    I've no idea, but you're using two different names - cod_pacient and cod_patient
     
    PoPSiCLe, Jan 28, 2015 IP
  3. labonica_labonica

    labonica_labonica Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Hi, PopSSiCle.

    I made a mistake in typing the primary keys. The correct is cod_patient.
    I'm trying here, I've read the documentation and could certify that the command is correct.
    Do I need to do some setting on my MySql?
    I'm really lost.

    Thank you for your interest in helping me. :)
     
    labonica_labonica, Jan 30, 2015 IP
  4. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #4
    This might sound silly, but make sure the database user has write permissions.

    Secondly, although the return type of count() is INT, but make sure that total_patient variable is getting the returned value correctly.
    I once ended up in a similar problem and the solution was to get the row[1] in returned result instead of row[0].
    Print the value of total_patient before running the update query to see what's in it.

    Good luck
     
    JEET, Jan 30, 2015 IP