Добрый день,
Проводим импорт в рабочую базу данных из Excel.
Для прописывания средств связи из карточки КА в закладку/деталь (для использования в рассылках) используем скрипт (прилагается).
Происходит дублирование уже имеющихся средств связи в закладке/детали КА.
Подскажите что и как дописать чтобы не допустить дубли - может поставить ограничение на дату создания записи?
Заранее спасибо.
declare @Communication1TypeID uniqueidentifier
declare @Communication2TypeID uniqueidentifier
declare @Communication3TypeID uniqueidentifier
declare @Communication4TypeID uniqueidentifier
declare @Communication5TypeID uniqueidentifier
declare @Communication1 nvarchar(250)
declare @Communication2 nvarchar(250)
declare @Communication3 nvarchar(250)
declare @Communication4 nvarchar(250)
declare @Communication5 nvarchar(250)
declare @AccountID uniqueidentifier
declare [Account_Cursor] cursor FOR
SELECT ID, Communication1TypeID, Communication2TypeID, Communication3TypeID,
Communication4TypeID, Communication5TypeID,
Communication1, Communication2, Communication3, Communication4, Communication5
FROM tbl_Account
open [Account_Cursor]
while (1 = 1)
begin
fetch next FROM [Account_Cursor]
INTO @AccountID, @Communication1TypeID, @Communication2TypeID, @Communication3TypeID,
@Communication4TypeID, @Communication5TypeID,
@Communication1, @Communication2, @Communication3, @Communication4, @Communication5
IF @@fetch_status = -1 break
IF @@fetch_status = -2 continue
IF NOT (@Communication1 IS NULL)
begin
INSERT INTO tbl_AccountCommunication
(AccountID, Number, CommunicationTypeID, Position)
VALUES (@AccountID, @Communication1, @Communication1TypeID, 1)
end
IF NOT (@Communication2 IS NULL)
begin
INSERT INTO tbl_AccountCommunication
(AccountID, Number, CommunicationTypeID, Position)
VALUES (@AccountID, @Communication2, @Communication2TypeID, 2)
end
IF NOT (@Communication3 IS NULL)
begin
INSERT INTO tbl_AccountCommunication
(AccountID, Number, CommunicationTypeID, Position)
VALUES (@AccountID, @Communication3, @Communication3TypeID, 3)
end
IF NOT (@Communication4 IS NULL)
begin
INSERT INTO tbl_AccountCommunication
(AccountID, Number, CommunicationTypeID, Position)
VALUES (@AccountID, @Communication4, @Communication4TypeID, 4)
end
IF NOT (@Communication5 IS NULL)
begin
INSERT INTO tbl_AccountCommunication
(AccountID, Number, CommunicationTypeID, Position)
VALUES (@AccountID, @Communication5, @Communication5TypeID, 5)
end
end
close [Account_Cursor]
deallocate [Account_Cursor]