Trigger SQL server avec des données sur plusieurs bases

Fermé
pedro8854 - 26 mai 2021 à 08:56
jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 - 26 mai 2021 à 09:56
Bonjour,

un peu débutant en SQL, je souhaiterais faire un trigger sur notre CRM, ce trigger a pour but d'insérer une nouvelle ligne dans la table "Comm_link".
Le problème que je rencontre c'est qu'il faudrait que j'aille chercher les données à insérer dans 2 tables, la table Communication et la table Opportunité.

J'avais pensé naïvement faire quelque chose comme ça mais force est de constater que ça ne fonctionne pas :
[CODE]CREATE TRIGGER [dbo].[VD_Date_lendemain1]

ON [dbo].[Communication]

AFTER INSERT,UPDATE

AS

BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

-- Insert statements for trigger here

INSERT INTO [dbo].[Comm_Link]
(
[CmLi_Comm_UserId],
[CmLi_Comm_CommunicationId],
[CmLi_CreatedBy],
[CmLi_CreatedDate],
[CmLi_UpdatedBy],
[CmLi_UpdatedDate],
[CmLi_Comm_CompanyId],
[CmLi_Comm_PersonId]
)

SELECT
CmLi_Comm_UserId = Comm_CreatedBy,
CmLi_Comm_CommunicationId = Comm_CommunicationId,
CmLi_CreatedBy = Comm_CreatedBy,
CmLi_CreatedDate = Comm_ToDateTime,
CmLi_UpdatedBy = Comm_UpdatedBy,
CmLi_UpdatedDate = Comm_UpdatedDate,
CmLi_Comm_CompanyId = Oppo_PrimaryCompanyId,
CmLi_Comm_PersonId = Oppo_PrimaryPersonId


FROM dbo.Communication inner join dbo.opportunity ON Oppo_OpportunityId = Comm_OpportunityId
inner join dbo.Comm_Link ON Comm_CommunicationId = CmLi_Comm_CommunicationId



WHERE Comm_Action = 'Meeting'

END[/CODE]

Je ne sais pas si c'est possible au final ? Merci d'avance de votre aide



Configuration: Windows / Chrome 90.0.4430.212

1 réponse

jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
26 mai 2021 à 09:56
Bonjour

Que viennent faire les = dans le SELECT de ta sous requête ??

Mis oui c'est faisable...

Commence par écrire et tester ta requête sans la mettre dans une procédure... Et une fois la requête trouvée, la, tu pourras créer ta proc.
0