Stored Procedures [dbo].[XLedgerBeginNewSyncHistory]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@syncEntityNamenvarchar(32)64
@startedAtdatetimeoffset10
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
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 -- let c sharp throw when no record successfully returned

end
GO
GRANT EXECUTE ON  [dbo].[XLedgerBeginNewSyncHistory] TO [MssExec]
GO
Uses