[dbo].[AttachDocumentsToOutgoingEmail]
CREATE PROCEDURE [dbo].[AttachDocumentsToOutgoingEmail]
@inOutgoingEmailId int,
@inMssDocuments PriKeyToIntMap readonly,
@inInvoicedHeaders PriKeyToIntMap readonly
AS
begin
set nocount on
insert into OutgoingEmailDocumentAttachment(
OutgoingEmailFID,
MssDocumentFID,
AttachmentOrder
)
select @inOutgoingEmailId,
MssDocumentFID = Documents.Id,
AttachmentOrder = min(Documents.[Value])
from @inMssDocuments Documents
group by Documents.Id
insert into OutgoingEmailInvoiceAttachment(
OutgoingEmailFID,
InvoicedHeaderFID,
AttachmentOrder
)
select @inOutgoingEmailId,
InvoicedHeaderFID = InvoicedHeaders.Id,
AttachmentOrder = min(InvoicedHeaders.[Value])
from @inInvoicedHeaders InvoicedHeaders
group by InvoicedHeaders.Id
end
GO
GRANT EXECUTE ON [dbo].[AttachDocumentsToOutgoingEmail] TO [MssExec]
GO