spImport_EmailSubscribers
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@EmailListID | int | IN | |
@SubscribersXML | ntext | IN |
Definition
Copy
create procedure [dbo].[spImport_EmailSubscribers](
@EmailListID int ,
@SubscribersXML ntext
)
as
begin
DECLARE @Subscribers TABLE (REID int, ClientUserID int, BackofficePeopleID int)
declare @idoc int
exec sp_xml_preparedocument @idoc output, @SubscribersXML
insert into @Subscribers (REID)
select REID from openxml(@idoc, '/root/user', 1) with (reid int)
update @Subscribers set ClientUserID=
(select top 1 cu.id from dbo.clientusers cu inner join dbo.backofficesystemusers bosu on cu.id=bosu.ClientUsersID
inner join dbo.BackOfficeSystemPeople peeps on peeps.id=bosu.BackofficePeopleID
where peeps.BackOfficeSystemID=0 and peeps.BackofficeRecordID = REID)
update @Subscribers set BackofficePeopleID=
(select ID from BackOfficeSystemPeople
where REID=BackOfficeSystemPeople.BackofficeRecordID and BackOfficeSystemPeople.BackOfficeSystemID=0)
insert into BackOfficeSystemPeople (BackOfficeSystemID,BackofficeRecordID)
select 0, REID from @Subscribers where BackofficePeopleID is null
update @Subscribers set BackofficePeopleID=
(select ID from BackOfficeSystemPeople
where REID=BackOfficeSystemPeople.BackofficeRecordID and BackOfficeSystemPeople.BackOfficeSystemID=0)
insert EmailList_Subscription (EmailListID, UserId, BackofficeSystemPeopleID)
select @EmailListID, ClientUserID, BackofficePeopleID from @Subscribers s where not exists (select ID from EmailList_Subscription where EmailList_Subscription.BackofficeSystemPeopleID=s.BackofficePeopleID and EmailList_Subscription.EmailListID=@EmailListID)
end