Sous SQL server, j'ai une procédure stockée qui contient une déclaration
d'un curseur :
DECLARE Duplicate_Read CURSOR
FOR
SELECT Contact_Kept, Contact_Lost
FROM Duplicates
FOR UPDATE
OPEN Duplicate_Read
Ensuite, je boucle sur ce curseur pour mettre à jour d'autres tables
n'appartenant pas au curseur mais en utilisant les champs retournés par le
curseur :
UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE Contact_id
= @Contact_Lost_Id
Or la mise à jour sur des tables ne se fait pas... !!!
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Fred BROUARD
poste la procédure dans son intégralité...
A +
Nico a écrit:
Bonjour...
Sous SQL server, j'ai une procédure stockée qui contient une déclaration d'un curseur :
DECLARE Duplicate_Read CURSOR FOR SELECT Contact_Kept, Contact_Lost FROM Duplicates FOR UPDATE
OPEN Duplicate_Read
Ensuite, je boucle sur ce curseur pour mettre à jour d'autres tables n'appartenant pas au curseur mais en utilisant les champs retournés par le curseur :
UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id
Or la mise à jour sur des tables ne se fait pas... !!!
Quelqu'un saurait-il m'expliquer pourquoi ?
Merci d'avance...
-- Frédéric BROUARD, MVP MS SQL Server. Expert Langage SQL / Delphi / web Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com ************************ www.datasapiens.com *************************
poste la procédure dans son intégralité...
A +
Nico a écrit:
Bonjour...
Sous SQL server, j'ai une procédure stockée qui contient une déclaration
d'un curseur :
DECLARE Duplicate_Read CURSOR
FOR
SELECT Contact_Kept, Contact_Lost
FROM Duplicates
FOR UPDATE
OPEN Duplicate_Read
Ensuite, je boucle sur ce curseur pour mettre à jour d'autres tables
n'appartenant pas au curseur mais en utilisant les champs retournés par le
curseur :
UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE Contact_id
= @Contact_Lost_Id
Or la mise à jour sur des tables ne se fait pas... !!!
Quelqu'un saurait-il m'expliquer pourquoi ?
Merci d'avance...
--
Frédéric BROUARD, MVP MS SQL Server. Expert Langage SQL / Delphi / web
Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html
Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com
************************ www.datasapiens.com *************************
Sous SQL server, j'ai une procédure stockée qui contient une déclaration d'un curseur :
DECLARE Duplicate_Read CURSOR FOR SELECT Contact_Kept, Contact_Lost FROM Duplicates FOR UPDATE
OPEN Duplicate_Read
Ensuite, je boucle sur ce curseur pour mettre à jour d'autres tables n'appartenant pas au curseur mais en utilisant les champs retournés par le curseur :
UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id
Or la mise à jour sur des tables ne se fait pas... !!!
Quelqu'un saurait-il m'expliquer pourquoi ?
Merci d'avance...
-- Frédéric BROUARD, MVP MS SQL Server. Expert Langage SQL / Delphi / web Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com ************************ www.datasapiens.com *************************
Nico
Bonjour,
Voici ce que ça donne :
CREATE PROCEDURE [dbo].[Proceed_CRM_Contacts_Duplicates] AS
/* DECLARATION DU CURSEUR DES CONTACTS A MODIFIER */ DECLARE Duplicate_Read CURSOR FOR SELECT Contact_Kept, Contact_Lost FROM Duplicates FOR UPDATE
OPEN Duplicate_Read
/* BOUCLE LECTURE DES DOUBLONS */ FETCH NEXT FROM Duplicate_Read INTO @Contact_Kept, @Contact_Lost
WHILE (@@FETCH_STATUS <> -1) BEGIN IF (@@FETCH_STATUS <> -2) BEGIN SET @Contact_Kept_Id = NULL SET @Contact_Lost_Id = NULL SET @Contact_Kept_Id = (SELECT Contact_id FROM Contact WHERE Cl_Customer_Code = @Contact_Kept) SET @Contact_Lost_Id = (SELECT Contact_id FROM Contact WHERE Cl_Customer_Code = @Contact_Lost) IF @Contact_Kept_Id <> NULL AND @Contact_Lost_Id <> NULL BEGIN BEGIN TRANSACTION UPDATE Rn_Appointments SET Contact = @Contact_Kept_Id WHERE Contact @Contact_Lost_Id UPDATE Connection_ SET Connected_contact_id = @Contact_Kept_Id WHERE Connected_contact_id = @Contact_Lost_Id UPDATE Connection_ SET Focal_contact_id = @Contact_Kept_Id WHERE Focal_contact_id = @Contact_Lost_Id UPDATE Cosmetovigilance SET Cl_Patient = @Contact_Kept_Id WHERE Cl_Patient = @Contact_Lost_Id UPDATE Cosmetovigilance SET Cl_Doctor = @Contact_Kept_Id WHERE Cl_Doctor @Contact_Lost_Id UPDATE Replies SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id UPDATE Fulfillment_event SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id UPDATE Survey_Results SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id UPDATE Reply_products SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id UPDATE Contact_Group SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id UPDATE Incentive_Alt_Address SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id UPDATE Incentive_Gifts SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id UPDATE Contact_Suggest SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id COMMIT TRANSACTION
/* BOUCLE MAJ DES MAILINGS */ DECLARE Mailings_Read CURSOR FOR SELECT Appt_Description, CL_Mailing_Desc FROM Mailings WHERE Contact = @Contact_Lost_Id FOR UPDATE
OPEN Mailings_Read
FETCH NEXT FROM Mailings_Read INTO @Appt_Description, @CL_Mailing_Desc
WHILE (@@FETCH_STATUS <> -1) BEGIN IF (@@FETCH_STATUS <> -2) BEGIN DELETE FROM Mailings WHERE Contact = @Contact_Lost_Id AND Appt_Description = @Appt_Description AND Appt_Description IN (SELECT Appt_Description FROM Mailings WHERE Contact = @Contact_Kept_Id AND Appt_Description = @Appt_Description) AND CL_Mailing_Desc @CL_Mailing_Desc AND CL_Mailing_Desc IN (SELECT CL_Mailing_Desc FROM Mailings WHERE Contact = @Contact_Kept_Id AND CL_Mailing_Desc = @CL_Mailing_Desc) END FETCH NEXT FROM Mailings_Read INTO @Appt_Description, @CL_Mailing_Desc END
CLOSE Mailings_Read DEALLOCATE Mailings_Read
UPDATE Mailings SET Contact = @Contact_Kept_Id WHERE Contact @Contact_Lost_Id
/* FIN MAJ MAILINGS */
END END FETCH NEXT FROM Duplicate_Read INTO @Contact_Kept, @Contact_Lost END
CLOSE Duplicate_Read DEALLOCATE Duplicate_Read GO
"Fred BROUARD" a écrit dans le message de news:
poste la procédure dans son intégralité...
A +
Nico a écrit: > Bonjour... > > Sous SQL server, j'ai une procédure stockée qui contient une déclaration > d'un curseur : > > DECLARE Duplicate_Read CURSOR > FOR > SELECT Contact_Kept, Contact_Lost > FROM Duplicates > FOR UPDATE > > OPEN Duplicate_Read > > Ensuite, je boucle sur ce curseur pour mettre à jour d'autres tables > n'appartenant pas au curseur mais en utilisant les champs retournés par
le
> curseur : > > UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE
Contact_id
> = @Contact_Lost_Id > > Or la mise à jour sur des tables ne se fait pas... !!! > > Quelqu'un saurait-il m'expliquer pourquoi ? > > Merci d'avance... > >
-- Frédéric BROUARD, MVP MS SQL Server. Expert Langage SQL / Delphi / web Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com ************************ www.datasapiens.com *************************
Bonjour,
Voici ce que ça donne :
CREATE PROCEDURE [dbo].[Proceed_CRM_Contacts_Duplicates] AS
/* DECLARATION DU CURSEUR DES CONTACTS A MODIFIER */
DECLARE Duplicate_Read CURSOR
FOR
SELECT Contact_Kept, Contact_Lost
FROM Duplicates
FOR UPDATE
OPEN Duplicate_Read
/* BOUCLE LECTURE DES DOUBLONS */
FETCH NEXT FROM Duplicate_Read INTO @Contact_Kept, @Contact_Lost
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
SET @Contact_Kept_Id = NULL
SET @Contact_Lost_Id = NULL
SET @Contact_Kept_Id = (SELECT Contact_id FROM Contact WHERE
Cl_Customer_Code = @Contact_Kept)
SET @Contact_Lost_Id = (SELECT Contact_id FROM Contact WHERE
Cl_Customer_Code = @Contact_Lost)
IF @Contact_Kept_Id <> NULL AND @Contact_Lost_Id <> NULL
BEGIN
BEGIN TRANSACTION
UPDATE Rn_Appointments SET Contact = @Contact_Kept_Id WHERE Contact @Contact_Lost_Id
UPDATE Connection_ SET Connected_contact_id = @Contact_Kept_Id WHERE
Connected_contact_id = @Contact_Lost_Id
UPDATE Connection_ SET Focal_contact_id = @Contact_Kept_Id WHERE
Focal_contact_id = @Contact_Lost_Id
UPDATE Cosmetovigilance SET Cl_Patient = @Contact_Kept_Id WHERE Cl_Patient
= @Contact_Lost_Id
UPDATE Cosmetovigilance SET Cl_Doctor = @Contact_Kept_Id WHERE Cl_Doctor @Contact_Lost_Id
UPDATE Replies SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id
UPDATE Fulfillment_event SET Contact_id = @Contact_Kept_Id WHERE
Contact_id = @Contact_Lost_Id
UPDATE Survey_Results SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id
UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE Contact_id
= @Contact_Lost_Id
UPDATE Reply_products SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id
UPDATE Contact_Group SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id
UPDATE Incentive_Alt_Address SET Contact_id = @Contact_Kept_Id WHERE
Contact_id = @Contact_Lost_Id
UPDATE Incentive_Gifts SET Contact_id = @Contact_Kept_Id WHERE Contact_id
= @Contact_Lost_Id
UPDATE Contact_Suggest SET Contact_id = @Contact_Kept_Id WHERE Contact_id
= @Contact_Lost_Id
COMMIT TRANSACTION
/* BOUCLE MAJ DES MAILINGS */
DECLARE Mailings_Read CURSOR
FOR
SELECT Appt_Description, CL_Mailing_Desc
FROM Mailings
WHERE Contact = @Contact_Lost_Id
FOR UPDATE
OPEN Mailings_Read
FETCH NEXT FROM Mailings_Read INTO @Appt_Description, @CL_Mailing_Desc
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
DELETE FROM Mailings WHERE Contact = @Contact_Lost_Id AND
Appt_Description = @Appt_Description
AND Appt_Description IN (SELECT Appt_Description FROM Mailings WHERE
Contact = @Contact_Kept_Id
AND Appt_Description = @Appt_Description) AND CL_Mailing_Desc @CL_Mailing_Desc
AND CL_Mailing_Desc IN (SELECT CL_Mailing_Desc FROM Mailings WHERE
Contact = @Contact_Kept_Id
AND CL_Mailing_Desc = @CL_Mailing_Desc)
END
FETCH NEXT FROM Mailings_Read INTO @Appt_Description, @CL_Mailing_Desc
END
CLOSE Mailings_Read
DEALLOCATE Mailings_Read
UPDATE Mailings SET Contact = @Contact_Kept_Id WHERE Contact @Contact_Lost_Id
/* FIN MAJ MAILINGS */
END
END
FETCH NEXT FROM Duplicate_Read INTO @Contact_Kept, @Contact_Lost
END
CLOSE Duplicate_Read
DEALLOCATE Duplicate_Read
GO
"Fred BROUARD" <brouardf@club-internet.fr> a écrit dans le message de
news:40B49F31.7030609@club-internet.fr...
poste la procédure dans son intégralité...
A +
Nico a écrit:
> Bonjour...
>
> Sous SQL server, j'ai une procédure stockée qui contient une déclaration
> d'un curseur :
>
> DECLARE Duplicate_Read CURSOR
> FOR
> SELECT Contact_Kept, Contact_Lost
> FROM Duplicates
> FOR UPDATE
>
> OPEN Duplicate_Read
>
> Ensuite, je boucle sur ce curseur pour mettre à jour d'autres tables
> n'appartenant pas au curseur mais en utilisant les champs retournés par
le
> curseur :
>
> UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE
Contact_id
> = @Contact_Lost_Id
>
> Or la mise à jour sur des tables ne se fait pas... !!!
>
> Quelqu'un saurait-il m'expliquer pourquoi ?
>
> Merci d'avance...
>
>
--
Frédéric BROUARD, MVP MS SQL Server. Expert Langage SQL / Delphi / web
Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html
Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com
************************ www.datasapiens.com *************************
/* DECLARATION DU CURSEUR DES CONTACTS A MODIFIER */ DECLARE Duplicate_Read CURSOR FOR SELECT Contact_Kept, Contact_Lost FROM Duplicates FOR UPDATE
OPEN Duplicate_Read
/* BOUCLE LECTURE DES DOUBLONS */ FETCH NEXT FROM Duplicate_Read INTO @Contact_Kept, @Contact_Lost
WHILE (@@FETCH_STATUS <> -1) BEGIN IF (@@FETCH_STATUS <> -2) BEGIN SET @Contact_Kept_Id = NULL SET @Contact_Lost_Id = NULL SET @Contact_Kept_Id = (SELECT Contact_id FROM Contact WHERE Cl_Customer_Code = @Contact_Kept) SET @Contact_Lost_Id = (SELECT Contact_id FROM Contact WHERE Cl_Customer_Code = @Contact_Lost) IF @Contact_Kept_Id <> NULL AND @Contact_Lost_Id <> NULL BEGIN BEGIN TRANSACTION UPDATE Rn_Appointments SET Contact = @Contact_Kept_Id WHERE Contact @Contact_Lost_Id UPDATE Connection_ SET Connected_contact_id = @Contact_Kept_Id WHERE Connected_contact_id = @Contact_Lost_Id UPDATE Connection_ SET Focal_contact_id = @Contact_Kept_Id WHERE Focal_contact_id = @Contact_Lost_Id UPDATE Cosmetovigilance SET Cl_Patient = @Contact_Kept_Id WHERE Cl_Patient = @Contact_Lost_Id UPDATE Cosmetovigilance SET Cl_Doctor = @Contact_Kept_Id WHERE Cl_Doctor @Contact_Lost_Id UPDATE Replies SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id UPDATE Fulfillment_event SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id UPDATE Survey_Results SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id UPDATE Reply_products SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id UPDATE Contact_Group SET Contact_id = @Contact_Kept_Id WHERE Contact_id @Contact_Lost_Id UPDATE Incentive_Alt_Address SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id UPDATE Incentive_Gifts SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id UPDATE Contact_Suggest SET Contact_id = @Contact_Kept_Id WHERE Contact_id = @Contact_Lost_Id COMMIT TRANSACTION
/* BOUCLE MAJ DES MAILINGS */ DECLARE Mailings_Read CURSOR FOR SELECT Appt_Description, CL_Mailing_Desc FROM Mailings WHERE Contact = @Contact_Lost_Id FOR UPDATE
OPEN Mailings_Read
FETCH NEXT FROM Mailings_Read INTO @Appt_Description, @CL_Mailing_Desc
WHILE (@@FETCH_STATUS <> -1) BEGIN IF (@@FETCH_STATUS <> -2) BEGIN DELETE FROM Mailings WHERE Contact = @Contact_Lost_Id AND Appt_Description = @Appt_Description AND Appt_Description IN (SELECT Appt_Description FROM Mailings WHERE Contact = @Contact_Kept_Id AND Appt_Description = @Appt_Description) AND CL_Mailing_Desc @CL_Mailing_Desc AND CL_Mailing_Desc IN (SELECT CL_Mailing_Desc FROM Mailings WHERE Contact = @Contact_Kept_Id AND CL_Mailing_Desc = @CL_Mailing_Desc) END FETCH NEXT FROM Mailings_Read INTO @Appt_Description, @CL_Mailing_Desc END
CLOSE Mailings_Read DEALLOCATE Mailings_Read
UPDATE Mailings SET Contact = @Contact_Kept_Id WHERE Contact @Contact_Lost_Id
/* FIN MAJ MAILINGS */
END END FETCH NEXT FROM Duplicate_Read INTO @Contact_Kept, @Contact_Lost END
CLOSE Duplicate_Read DEALLOCATE Duplicate_Read GO
"Fred BROUARD" a écrit dans le message de news:
poste la procédure dans son intégralité...
A +
Nico a écrit: > Bonjour... > > Sous SQL server, j'ai une procédure stockée qui contient une déclaration > d'un curseur : > > DECLARE Duplicate_Read CURSOR > FOR > SELECT Contact_Kept, Contact_Lost > FROM Duplicates > FOR UPDATE > > OPEN Duplicate_Read > > Ensuite, je boucle sur ce curseur pour mettre à jour d'autres tables > n'appartenant pas au curseur mais en utilisant les champs retournés par
le
> curseur : > > UPDATE Product_Remarks SET Contact_id = @Contact_Kept_Id WHERE
Contact_id
> = @Contact_Lost_Id > > Or la mise à jour sur des tables ne se fait pas... !!! > > Quelqu'un saurait-il m'expliquer pourquoi ? > > Merci d'avance... > >
-- Frédéric BROUARD, MVP MS SQL Server. Expert Langage SQL / Delphi / web Livre SQL - col. Référence : http://sqlpro.developpez.com/bookSQL.html Le site du SQL, pour débutants et pros : http://sqlpro.developpez.com ************************ www.datasapiens.com *************************