Trigger SQL server avec des données sur plusieurs bases
pedro8854
-
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
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
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
A voir également:
- Les données de chaîne ou binaires seront tronquées.
- Fuite données maif - Guide
- Supprimer les données de navigation - Guide
- Chaine tnt gratuite sur mobile - Guide
- Plus de chaine tv - Guide
- Chaine radio - Télécharger - Médias et Actualité