F
F
Fyodor2015-08-12 21:17:34
SQL Server
Fyodor, 2015-08-12 21:17:34

How to deal with a trigger in MSSQL - modify it so that CRM does not notice?

There is one windows crm with a database in MSSQL 2008, and in the customer table there, phones are entered without any mask, i.e. just as a person wrote, the phone was saved in the database. Accordingly, there are additional characters and spaces, and anything can be. And you need to search by phone number.
I decided to add a metaphone field to the table and make a trigger

SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER dbo.relation_new_triu ON dbo.relation
WITH EXECUTE AS CALLER
FOR INSERT, UPDATE
AS
BEGIN
 UPDATE dbo.relation SET metaphone = dbo.ExtractInteger(phone) 
END
GO

ALTER TABLE dbo.relation
DISABLE TRIGGER relation_new_triu
GO

its essence is such that only the digital part of the record being added-updated is taken from the phone field and entered into the metaphone field (and we are already looking for it)
in mssql based on I try - everything is successful. but CRM does not like this turn, writes an error Update affected more than 1 row. Is there any way to bypass it? not strong in triggers, unfortunately ... if this option does not work, it only comes to mind to create a certain task that will update the data every few minutes ...
in theory, you can fill in metaphone only if the field is empty, after that the phone field rarely changes.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2015-08-13
@Richard_Ferlow

You can rewrite the query with a join by joining it with the inserted table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question