IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SQL Procédural MySQL Discussion :

Besion d'aide sur une procédure stockée


Sujet :

SQL Procédural MySQL

  1. #1
    Membre éclairé
    Homme Profil pro
    Ingénieur d'études en développements techniques
    Inscrit en
    Novembre 2005
    Messages
    244
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur d'études en développements techniques
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Novembre 2005
    Messages : 244
    Par défaut Besion d'aide sur une procédure stockée
    Bonjour,

    Voici une procédure stockée que j'aimerai modifier : j'aimerai ajouter un catch pour gérer l'absence de résultats pour setter des valeurs manuellement concernant cette section :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
     -- Vérification de l'existence du client
            SELECT COUNT(*) INTO n_enreg
              FROM finalclients
             WHERE client_id_pms = c1_resa_num_client_pms;
     
            -- Si le client existe on CONTINUE
            IF n_enreg > 0 THEN ==> j'aimerai gérer le où on ne trouve pas d'enregistrement
    Voici le code global

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
     
    BLOCK1: BEGIN
        DECLARE c1_resa_num_pms VARCHAR(32);
        DECLARE c1_room VARCHAR(32);
        DECLARE c1_resa_num_client_pms VARCHAR(32);
        DECLARE c2_date_nuitee VARCHAR(32);
        DECLARE c2_depart VARCHAR(32);
        DECLARE c2_resa_montant VARCHAR(32);
        DECLARE n_enreg INT;
        DECLARE resaClientId INT;
        DECLARE resaMontantTotal INT;
        DECLARE resaDateMeilleureNuitee VARCHAR(32);
        DECLARE resaMeilleureNuiteeMontant INT;
        DECLARE resaDateArrivee VARCHAR(32);
        DECLARE resaDateDepart VARCHAR(32);
        DECLARE resaNbNuitee INT;
        DECLARE resaPMS VARCHAR(32);
        DECLARE resaBlocDirecteur INT;
        DECLARE clientOptinPS INT;
        DECLARE clientOptinPromo INT;
        DECLARE b_First BOOLEAN;
        DECLARE dateDuJour VARCHAR(32);
        DECLARE resaOutilPms VARCHAR(32) DEFAULT("FIDELIO");
        DECLARE resaHotel VARCHAR(32);
        DECLARE resaDate VARCHAR(32);
        DECLARE resaStatus VARCHAR(32);
        DECLARE resaPeriode VARCHAR(32) DEFAULT 'Indefini';
        DECLARE resaSource VARCHAR(255);
        DECLARE resaDiscrimiant_r VARCHAR(255);
        DECLARE resaDateUpdate VARCHAR(255);
        DECLARE resaNbAdults INT;
        DECLARE resaNbChilds INT;
        DECLARE resaRateCode VARCHAR(32);
        DECLARE resaStatutChambre INT;
        DECLARE resaRoomRevenue INT;
        DECLARE resaOherRevenue INT;
        DECLARE resaFoodRevenue INT;
        DECLARE resaTotalRevenue INT;
        DECLARE resaTotalRoomTax INT;
        DECLARE resaTotalOtherTax INT;
        DECLARE resaTotalTax INT;
        DECLARE resaDateFlag VARCHAR(32);
        DECLARE resaLock INT;
        DECLARE diffDepart INT;
        DECLARE diffArrivee INT;
     
     
        DECLARE compteur1 INT DEFAULT 0;
        DECLARE compteur2 INT DEFAULT 0;
        DECLARE compteur2_total INT DEFAULT 0;
     
        DECLARE no_more_rows1 BOOLEAN DEFAULT FALSE;
     
        -- Curseur qui regroupe toutes les réservations de la table temporaire
        DECLARE curseur1 CURSOR FOR
        SELECT resa_num_pms, room, resa_num_client_pms
          FROM fidelioresaslivelocal
        GROUP BY resa_num_pms, room, resa_num_client_pms;
     
        DECLARE CONTINUE handler FOR NOT FOUND SET no_more_rows1 = TRUE;
     
        -- Parcours du 1er curseur (réservations)
        OPEN curseur1;
        LOOP1: LOOP
            FETCH curseur1 INTO c1_resa_num_pms, c1_room, c1_resa_num_client_pms;
            IF no_more_rows1 THEN
                CLOSE curseur1;
                LEAVE LOOP1;
            END IF;
            SET compteur1 = compteur1 + 1;
     
            -- Initialisation des variables
            SET compteur2 = 0;
            SET resaClientId = NULL;
            SET b_First = TRUE;
            SET resaDateArrivee = NULL;
            SET resaDateDepart = NULL;
            SET resaNbNuitee = 0;
            SET resaMontantTotal = 0;
            SET resaDateMeilleureNuitee = NULL;
            SET resaMeilleureNuiteeMontant = 0;
     
            -- Vérification de l'existence du client
            SELECT COUNT(*) INTO n_enreg
              FROM finalclients
             WHERE client_id_pms = c1_resa_num_client_pms;
     
            -- Si le client existe on CONTINUE
            IF n_enreg > 0 THEN
                -- Parcours du 2nd curseur (lignes d'une réservation)
                BLOCK2: BEGIN
                    DECLARE no_more_rows2 BOOLEAN DEFAULT FALSE;
     
                    -- Curseur qui concerne toutes les lignes d'une même réservation
                    DECLARE curseur2 CURSOR FOR
                    SELECT date_nuitee, depart, resa_montant, 'FIDELIO', discriminant_r, resa_date, resa_source, resa_statut, discriminant_r, date_update_resa, nb_adults, 
                           nb_children, rate_code, statut_resa_chambre, room_revenue, other_revenue, food_revenue, total_revenue, total_room_tax, total_other_tax, total_tax
                      FROM fidelioresaslivelocal
                     WHERE resa_num_pms = c1_resa_num_pms
                    ORDER BY date_nuitee ASC;
     
                    DECLARE CONTINUE handler FOR NOT FOUND SET no_more_rows2 = TRUE;
     
                    OPEN curseur2;
                    LOOP2: LOOP
     
                        FETCH curseur2 INTO c2_date_nuitee, c2_depart, c2_resa_montant, resaOutilPms, resaHotel, resaDate, resaSource, resaStatus, resaDiscrimiant_r,
                        resaDateUpdate, resaNbAdults, resaNbChilds, resaRateCode, resaStatutChambre, resaRoomRevenue, resaOherRevenue, resaFoodRevenue, resaTotalRevenue,
                        resaTotalRoomTax, resaTotalOtherTax, resaTotalTax;
     
                        IF no_more_rows2 THEN
                            CLOSE curseur2;
                            LEAVE LOOP2;
                        END IF;
                        SET compteur2 = compteur2 + 1;
                        SET compteur2_total = compteur2_total + 1;
     
                        -- Si c'est le premier enregistrement il s'agit de la première nuit
                        IF b_First THEN
                            SET resaDateArrivee = c2_date_nuitee;
                            SET b_First = FALSE;
                        END IF;
     
                        IF IFNULL(c2_depart, 'N') = 'Y' THEN
                            -- Date de départ
                            SET resaDateDepart = c2_date_nuitee;
                        ELSE
                            -- Nombre de nuitées
                            SET resaNbNuitee = resaNbNuitee + 1;
     
                            -- Montant total
                            SET resaMontantTotal = resaMontantTotal + c2_resa_montant;
     
                            -- Meilleure nuitée
                            IF c2_resa_montant > resaMeilleureNuiteeMontant THEN
                                SET resaDateMeilleureNuitee = c2_date_nuitee;
                                SET resaMeilleureNuiteeMontant = c2_resa_montant;
                            END IF;
     
                            -- Resa Statut
                            IF (TO_DAYS(resaDateArrivee) - TO_DAYS(NOW()) > 0) THEN
                                SET resaPeriode = 'Client attendu';
                            ELSE
                                IF(TO_DAYS(resaDateDepart) - TO_DAYS(NOW()) >= 0) THEN
                                    SET resaPeriode = 'Client present';
                                ELSE
                                    SET resaPeriode = 'Client parti';
                                END IF;
                            END IF;
                        END IF;
                    END LOOP LOOP2;
                END BLOCK2;
     
                -- Vérification de l'existence de l'enregistrement dans la table finale
                SELECT COUNT(*) INTO n_enreg
                  FROM finalresas
                 WHERE resa_num_pms = c1_resa_num_pms
                   AND room = c1_room
                   AND resa_num_client_pms = c1_resa_num_client_pms;
     
                -- Récupération des infos du client
                SELECT DISTINCT IFNULL(client_id,0) AS client_id, IFNULL(optin_post_sejour, 1) AS optin_post_sejour, IFNULL(optin_email_promo, 1) AS optin_email_promo INTO resaClientId, clientOptinPS, clientOptinPromo
                  FROM finalclients
                 WHERE client_id_pms = c1_resa_num_client_pms;
     
                -- Si l'enregistrement existe on met à jour, sinon on insère...
                IF n_enreg > 0 THEN
                    UPDATE finalresas
                       SET resa_client_id = resaClientId,
                           resa_montant_total = resaMontantTotal,
                           resa_nb_nuitee = resaNbNuitee,
                           date_meilleure_nuitee = resaDateMeilleureNuitee,
                           resa_meilleure_nuitee_montant = resaMeilleureNuiteeMontant,
                           resa_date_arrivee = resaDateArrivee,
                           resa_date_depart = resaDateDepart,
                           resa_bloc_directeur = IF(((clientOptinPS = 0) && (clientOptinPromo = 0)), 1, 0),
                           resa_vip = IF((resaMeilleureNuiteeMontant >= get_seuil_vip_fidelio()), 1,0),
                           resa_outil_pms = resaOutilPms,
                           resa_hotel = resaHotel,
                           resa_date = resaDate,
                           resa_statut = resaStatus,
                           resa_periode = resaPeriode,
                           resa_source = resaSource,
                           discriminant_r = resaDiscrimiant_r,
                           date_update_resa = resaDateUpdate,
                           nb_adults = resaNbAdults,
                           nb_children = resaNbChilds,
                           rate_code = resaRateCode,
                           statut_resa_chambre = resaStatutChambre,
                           room_revenue = resaRoomRevenue,
                           other_revenue = resaOherRevenue,
                           food_revenue = resaFoodRevenue,
                           total_revenue = resaTotalRevenue,
                           total_room_tax = resaTotalRoomTax,
                           total_other_tax = resaTotalOtherTax,
                           total_tax = resaTotalTax,
                           date_flag = NOW()
     
                     WHERE resa_num_pms = c1_resa_num_pms
                       AND room = c1_room
                       AND resa_num_client_pms = c1_resa_num_client_pms;
                ELSE
                    INSERT INTO finalresas (resa_id, resa_num_pms, room, resa_num_client_pms, resa_client_id,
                                            resa_montant_total,
                                            resa_nb_nuitee, date_meilleure_nuitee, resa_meilleure_nuitee_montant,
                                            resa_date_arrivee, resa_date_depart,
                                            resa_bloc_directeur, resa_vip, resa_outil_pms, resa_hotel, resa_date, resa_statut, resa_periode, resa_source, discriminant_r, date_update_resa, nb_adults,
                                            nb_children, rate_code, statut_resa_chambre, room_revenue, other_revenue, food_revenue, total_revenue, total_room_tax, total_other_tax, total_tax, date_flag, resa_lock)
                                    VALUES (null, c1_resa_num_pms, c1_room, c1_resa_num_client_pms, resaClientId,
                                            resaMontantTotal,
                                            resaNbNuitee, resaDateMeilleureNuitee, resaMeilleureNuiteeMontant,
                                            resaDateArrivee, resaDateDepart,
                                            IF(((clientOptinPS = 0) && (clientOptinPromo = 0)), 1, 0), IF((resaMeilleureNuiteeMontant >= get_seuil_vip_fidelio()), 1,0), resaOutilPms, resaHotel, resaDate, resaStatus, resaPeriode, resaSource,
                                             resaDiscrimiant_r, resaDateUpdate, resaNbAdults, resaNbChilds, resaRateCode, resaStatutChambre, resaRoomRevenue, resaOherRevenue, resaFoodRevenue, resaTotalRevenue,
                                             resaTotalRoomTax, resaTotalOtherTax, resaTotalTax, NOW(), 0);
                END IF;
            END IF;
        END LOOP LOOP1;
    END BLOCK1
    D'avance merci pour votre aide

  2. #2
    Membre éclairé
    Homme Profil pro
    Ingénieur d'études en développements techniques
    Inscrit en
    Novembre 2005
    Messages
    244
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur d'études en développements techniques
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Novembre 2005
    Messages : 244
    Par défaut Réponse
    Voici le résultat auquel je suis arrivé, si ça peut aider quelqu'un je le partage :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
     
    BLOCK1: BEGIN
        DECLARE c1_resa_num_pms VARCHAR(32);
        DECLARE c1_room VARCHAR(32);
        DECLARE c1_resa_num_client_pms VARCHAR(32);
        DECLARE c2_date_nuitee VARCHAR(32);
        DECLARE c2_depart VARCHAR(32);
        DECLARE c2_resa_montant VARCHAR(32);
        DECLARE n_enreg1 INT;
        DECLARE n_enreg2 INT;
        DECLARE resaClientId INT;
        DECLARE resaMontantTotal INT;
        DECLARE resaDateMeilleureNuitee VARCHAR(32);
        DECLARE resaMeilleureNuiteeMontant INT;
        DECLARE resaDateArrivee VARCHAR(32);
        DECLARE resaDateDepart VARCHAR(32);
        DECLARE resaNbNuitee INT;
        DECLARE resaPMS VARCHAR(32);
        DECLARE resaBlocDirecteur INT;
        DECLARE clientOptinPS INT;
        DECLARE clientOptinPromo INT;
        DECLARE b_First BOOLEAN;
        DECLARE dateDuJour VARCHAR(32);
        DECLARE resaOutilPms VARCHAR(32) DEFAULT("PMS");
        DECLARE resaHotel VARCHAR(32);
        DECLARE resaDate VARCHAR(32);
        DECLARE resaStatus VARCHAR(32);
        DECLARE resaPeriode VARCHAR(32) DEFAULT 'Indefini';
        DECLARE resaSource VARCHAR(255);
        DECLARE resaDiscrimiant_r VARCHAR(255);
        DECLARE resaDateUpdate VARCHAR(255);
        DECLARE resaNbAdults INT;
        DECLARE resaNbChilds INT;
        DECLARE resaRateCode VARCHAR(32);
        DECLARE resaStatutChambre INT;
        DECLARE resaRoomRevenue INT;
        DECLARE resaOherRevenue INT;
        DECLARE resaFoodRevenue INT;
        DECLARE resaTotalRevenue INT;
        DECLARE resaTotalRoomTax INT;
        DECLARE resaTotalOtherTax INT;
        DECLARE resaTotalTax INT;
        DECLARE resaDateFlag VARCHAR(32);
        DECLARE resaLock INT;
     
        DECLARE compteur1 INT DEFAULT 0;
        DECLARE compteur2 INT DEFAULT 0;
        DECLARE compteur2_total INT DEFAULT 0;
     
        DECLARE no_more_rows1 BOOLEAN DEFAULT FALSE;
        DECLARE no_clients BOOLEAN DEFAULT FALSE;
     
        -- Curseur qui regroupe toutes les réservations de la table temporaire
        DECLARE curseur1 CURSOR FOR
        SELECT resa_num_pms, room, resa_num_client_pms
          FROM fidelioresaslivelocal
        GROUP BY resa_num_pms, room, resa_num_client_pms;
     
        DECLARE CONTINUE handler FOR NOT FOUND SET no_more_rows1 = TRUE;
     
        -- Parcours du 1er curseur (réservations)
        OPEN curseur1;
        LOOP1: LOOP
            FETCH curseur1 INTO c1_resa_num_pms, c1_room, c1_resa_num_client_pms;
            IF no_more_rows1 THEN
                CLOSE curseur1;
                LEAVE LOOP1;
            END IF;
            SET compteur1 = compteur1 + 1;
     
            -- Initialisation des variables
            SET compteur2 = 0;
            SET resaClientId = NULL;
            SET b_First = TRUE;
            SET resaDateArrivee = NULL;
            SET resaDateDepart = NULL;
            SET resaNbNuitee = 0;
            SET resaMontantTotal = 0;
            SET resaDateMeilleureNuitee = NULL;
            SET resaMeilleureNuiteeMontant = 0;
     
            -- Parcours du 2nd curseur (lignes d'une réservation)
            BLOCK2: BEGIN
                DECLARE no_more_rows2 BOOLEAN DEFAULT FALSE;
     
                -- Curseur qui concerne toutes les lignes d'une même réservation
                DECLARE curseur2 CURSOR FOR
                SELECT date_nuitee, depart, resa_montant, 'PMS', discriminant_r, resa_date, resa_source, resa_statut, discriminant_r, date_update_resa, nb_adults, 
                       nb_children, rate_code, statut_resa_chambre, room_revenue, other_revenue, food_revenue, total_revenue, total_room_tax, total_other_tax, total_tax
                  FROM fidelioresaslivelocal
                 WHERE resa_num_pms = c1_resa_num_pms
                ORDER BY date_nuitee ASC;
     
                DECLARE CONTINUE handler FOR NOT FOUND SET no_more_rows2 = TRUE;
     
                OPEN curseur2;
                LOOP2: LOOP
     
                    FETCH curseur2 INTO c2_date_nuitee, c2_depart, c2_resa_montant, resaOutilPms, resaHotel, resaDate, resaSource, resaStatus, resaDiscrimiant_r,
                    resaDateUpdate, resaNbAdults, resaNbChilds, resaRateCode, resaStatutChambre, resaRoomRevenue, resaOherRevenue, resaFoodRevenue, resaTotalRevenue,
                    resaTotalRoomTax, resaTotalOtherTax, resaTotalTax;
     
                    IF no_more_rows2 THEN
                        CLOSE curseur2;
                        LEAVE LOOP2;
                    END IF;
                    SET compteur2 = compteur2 + 1;
                    SET compteur2_total = compteur2_total + 1;
     
                    -- Si c'est le premier enregistrement il s'agit de la première nuit
                    IF b_First THEN
                        SET resaDateArrivee = c2_date_nuitee;
                        SET b_First = FALSE;
                    END IF;
     
    								-- Selection du nom de l'hotelsbif en FR
    								SELECT IFNULL(nom_hotel_fr, 'Sans nom !') INTO @nom_hotel
    								FROM hotelsbifhgp
    								WHERE discriminant = resaHotel
                    LIMIT 1;							
    								SET resaHotel = @nom_hotel;
     
     
                    -- Selection du resa_statut
                   SET @resaStatutCRM = IF(((resaStatus = 'NO SHOW') OR (resaStatus = 'CANCELLED')),'Annulée','OK');
                    /*SET @resaStatutCRM = resaStatus;*/
     
                    IF IFNULL(c2_depart, 'N') = 'Y' THEN
                        -- Date de départ
                        SET resaDateDepart = c2_date_nuitee;
                    ELSE
                        -- Nombre de nuitées
                        SET resaNbNuitee = resaNbNuitee + 1;
     
                        -- Montant total
                        SET resaMontantTotal = resaMontantTotal + c2_resa_montant;
     
                        -- Meilleure nuitée
                        IF c2_resa_montant > resaMeilleureNuiteeMontant THEN
                            SET resaDateMeilleureNuitee = c2_date_nuitee;
                            SET resaMeilleureNuiteeMontant = c2_resa_montant;
                        END IF;
     
                        -- Resa Statut
                        IF (TO_DAYS(resaDateArrivee) - TO_DAYS(NOW()) > 0) THEN
                            SET resaPeriode = 'Client attendu';
                        ELSE
                            IF(TO_DAYS(resaDateDepart) - TO_DAYS(NOW()) >= 0) THEN
                                SET resaPeriode = 'Client present';
                            ELSE
                                SET resaPeriode = 'Client parti';
                            END IF;
                        END IF;
                    END IF;
                END LOOP LOOP2;
            END BLOCK2;
     
            -- Vérification de l'existence du client
            SELECT COUNT(*) INTO n_enreg1
              FROM finalclients
             WHERE client_id_pms = c1_resa_num_client_pms;
     
            IF n_enreg1 = 0 THEN
                SET resaClientId = 0;
                SET clientOptinPS = 1;
                SET clientOptinPromo = 1;
            ELSE
                -- Récupération des infos du client
                SELECT DISTINCT client_id, optin_post_sejour, optin_email_promo INTO resaClientId, clientOptinPS, clientOptinPromo
                  FROM finalclients
                 WHERE client_id_pms = c1_resa_num_client_pms;
            END IF;
     
            -- Vérification de l'existence de l'enregistrement dans la table finale
            SELECT COUNT(*) INTO n_enreg2
              FROM finalresas
             WHERE resa_num_pms = c1_resa_num_pms
               AND room = c1_room
               AND resa_num_client_pms = c1_resa_num_client_pms;
     
            -- Si l'enregistrement existe on met à jour, sinon on insère...
            IF n_enreg2 > 0 THEN
                UPDATE finalresas
                   SET resa_client_id = resaClientId,
                       resa_montant_total = resaMontantTotal,
                       resa_nb_nuitee = resaNbNuitee,
                       date_meilleure_nuitee = resaDateMeilleureNuitee,
                       resa_meilleure_nuitee_montant = resaMeilleureNuiteeMontant,
                       resa_date_arrivee = resaDateArrivee,
                       resa_date_depart = resaDateDepart,
                       resa_bloc_directeur = IF(((clientOptinPS = 0) && (clientOptinPromo = 0)), 1, 0),
                       resa_vip = IF((resaMeilleureNuiteeMontant >= get_seuil_vip_fidelio()), 1,0),
                       resa_outil_pms = resaOutilPms,
                       resa_hotel = resaHotel,
                       resa_date = resaDate,
                       resa_statut = @resaStatutCRM,
                       resa_periode = resaPeriode,
                       resa_source = resaSource,
                       discriminant_r = resaDiscrimiant_r,
                       date_update_resa = resaDateUpdate,
                       nb_adults = resaNbAdults,
                       nb_children = resaNbChilds,
                       rate_code = resaRateCode,
                       statut_resa_chambre = resaStatutChambre,
                       room_revenue = resaRoomRevenue,
                       other_revenue = resaOherRevenue,
                       food_revenue = resaFoodRevenue,
                       total_revenue = resaTotalRevenue,
                       total_room_tax = resaTotalRoomTax,
                       total_other_tax = resaTotalOtherTax,
                       total_tax = resaTotalTax,
                       date_flag = NOW()
     
                 WHERE resa_num_pms = c1_resa_num_pms
                   AND room = c1_room
                   AND resa_num_client_pms = c1_resa_num_client_pms;
            ELSE
                INSERT INTO finalresas (resa_id, resa_num_pms, room, resa_num_client_pms, resa_client_id,
                                        resa_montant_total,
                                        resa_nb_nuitee, date_meilleure_nuitee, resa_meilleure_nuitee_montant,
                                        resa_date_arrivee, resa_date_depart,
                                        resa_bloc_directeur, resa_vip, resa_outil_pms, resa_hotel, resa_date, resa_statut, resa_periode, resa_source, discriminant_r, date_update_resa, nb_adults,
                                        nb_children, rate_code, statut_resa_chambre, room_revenue, other_revenue, food_revenue, total_revenue, total_room_tax, total_other_tax, total_tax, date_flag, resa_lock)
                                VALUES (null, c1_resa_num_pms, c1_room, c1_resa_num_client_pms, resaClientId,
                                        resaMontantTotal,
                                        resaNbNuitee, resaDateMeilleureNuitee, resaMeilleureNuiteeMontant,
                                        resaDateArrivee, resaDateDepart,
                                        IF(((clientOptinPS = 0) && (clientOptinPromo = 0)), 1, 0), IF((resaMeilleureNuiteeMontant >= get_seuil_vip_fidelio()), 1,0), resaOutilPms, resaHotel, resaDate, @resaStatutCRM, resaPeriode, resaSource,
                                         resaDiscrimiant_r, resaDateUpdate, resaNbAdults, resaNbChilds, resaRateCode, resaStatutChambre, resaRoomRevenue, resaOherRevenue, resaFoodRevenue, resaTotalRevenue,
                                         resaTotalRoomTax, resaTotalOtherTax, resaTotalTax, NOW(), 0);
            END IF;
            -- MAJ du client correspondant
            IF resaClientId > 0 THEN
    						CALL actions_post_update_clients(resaClientId);
            END IF;
     
        END LOOP LOOP1;		
    END BLOCK1

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Besoin d'aide sur une procédure stockée
    Par Ideal_Du_Gazeau dans le forum Développement
    Réponses: 4
    Dernier message: 18/02/2010, 17h59
  2. Aide sur une Procédure stockée
    Par NicoNGRI dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 10/12/2006, 00h48
  3. Gros Pb de perf sur une procédure stockée
    Par El Riiico dans le forum SQL Procédural
    Réponses: 5
    Dernier message: 05/05/2006, 15h51
  4. Réponses: 4
    Dernier message: 14/06/2004, 16h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo