Копирование средств связи Контактов из карточки на деталь

Всех приветствую!

Часто возникает ситуация, что после импорта Контактов, средства связи импортируются в карточку, но не появляются в деталях.

Чем это грозит?
Например, при массовой рассылке, если у контакта не будет e-mail на детали, то письмо не отправится.

Если используется СУБД MS SQL, то есть решение данной ситуации:

declare @Communication1TypeID uniqueidentifier
declare @Communication2TypeID uniqueidentifier
declare @Communication3TypeID uniqueidentifier
declare @Communication4TypeID uniqueidentifier
declare @Communication1 nvarchar(250)
declare @Communication2 nvarchar(250)
declare @Communication3 nvarchar(250)
declare @Communication4 nvarchar(250)
declare @ContactID uniqueidentifier

declare [Contact_Cursor] cursor FOR
        SELECT ID, Communication1TypeID, Communication2TypeID, Communication3TypeID,
                Communication4TypeID,
                Communication1, Communication2, Communication3, Communication4
        FROM tbl_Contact       
open [Contact_Cursor]

while (1 = 1)
begin
        fetch next FROM [Contact_Cursor]
        INTO @ContactID, @Communication1TypeID, @Communication2TypeID, @Communication3TypeID,
                @Communication4TypeID,
                @Communication1, @Communication2, @Communication3, @Communication4
        IF @@fetch_status = -1 break
        IF @@fetch_status = -2 continue
       
        IF NOT (@Communication1 IS NULL)
        begin
                INSERT INTO tbl_ContactCommunication
                        (ContactID, Number, CommunicationTypeID, Position)
                VALUES (@ContactID, @Communication1, @Communication1TypeID, 1)
        end
        IF NOT (@Communication2 IS NULL)
        begin
                INSERT INTO tbl_ContactCommunication
                        (ContactID, Number, CommunicationTypeID, Position)
                VALUES (@ContactID, @Communication2, @Communication2TypeID, 2)
        end
        IF NOT (@Communication3 IS NULL)
        begin
                INSERT INTO tbl_ContactCommunication
                        (ContactID, Number, CommunicationTypeID, Position)
                VALUES (@ContactID, @Communication3, @Communication3TypeID, 3)
        end
        IF NOT (@Communication4 IS NULL)
        begin
                INSERT INTO tbl_ContactCommunication
                        (ContactID, Number, CommunicationTypeID, Position)
                VALUES (@ContactID, @Communication4, @Communication4TypeID, 4)
        end
end
close [Contact_Cursor]
deallocate [Contact_Cursor]

Надеюсь, что данная информация будет полезна!

С уважением,
Белецкий Арсений
Группа компаний Terrasoft

Нравится

0 комментариев
Показать все комментарии