[dbo].[XLedgerBeginNewSyncHistory]
CREATE PROCEDURE [dbo].[XLedgerBeginNewSyncHistory]
@syncEntityName nvarchar(32),
@startedAt datetimeoffset
AS
begin
set nocount on
declare @id int
declare @entityTypeId int =
(
select XLedgerSyncEntityType.XLedgerSyncEntityTypeId
from XLedgerSyncEntityType
where XLedgerSyncEntityType.[Name] = @syncEntityName
)
declare @upToDateAsOf datetimeoffset =
(
select top 1 XLedgerSyncHistory.UpToDateAsOf
from XLedgerSyncHistory
where XLedgerSyncHistory.XLedgerSyncEntityTypeFid = @entityTypeId
order by XLedgerSyncHistory.UpToDateAsOf desc
)
insert into XLedgerSyncHistory
(
XLedgerSyncEntityTypeFid,
SyncStarted
)
select
XLedgerSyncEntityTypeFid = @entityTypeId,
SyncStarted = @startedAt
set @id = SCOPE_IDENTITY()
select
Item1 = @id,
Item2 = @upToDateAsOf
where @id is not null
end
GO
GRANT EXECUTE ON [dbo].[XLedgerBeginNewSyncHistory] TO [MssExec]
GO