1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

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.
    SEMrush
    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
    SEMrush
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    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:
    2,706
    Likes Received:
    210
    Best Answers:
    5
    Trophy Points:
    215
    #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