title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | f1_keywords | helpviewer_keywords | dev_langs | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sys.fn_cdc_decrement_lsn (Transact-SQL) |
sys.fn_cdc_decrement_lsn (Transact-SQL) |
rwestMSFT |
randolphwest |
09/29/2021 |
sql |
system-objects |
reference |
|
|
|
[!INCLUDE SQL Server]
Returns the previous log sequence number (LSN) in the sequence based upon the specified LSN.
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sys.fn_cdc_decrement_lsn ( lsn_value )
LSN value. lsn_value is binary(10).
binary(10)
The LSN returned by the function is always less than the specified value, and no LSN values can exist between the two values.
Requires membership in the public database role.
The following example uses sys.fn_cdc_decrement_lsn
to set the upper LSN boundary in a query that returns change data rows that have LSN values less than the maximum LSN value.
Use AdventureWorks2022;
GO
DECLARE @from_lsn binary(10), @to_lsn binary(10);
SET @from_lsn = sys.fn_cdc_get_min_lsn('HumanResources_Employee');
SET @to_lsn = sys.fn_cdc_decrement_lsn(sys.fn_cdc_get_max_lsn());
SELECT * FROM cdc.fn_cdc_get_all_changes_HumanResources_Employee( @from_lsn, @to_lsn, 'all');
GO
Note
Error 313 is expected if LSN range supplied is not appropriate when calling cdc.fn_cdc_get_all_changes_<capture_instance>
or cdc.fn_cdc_get_net_changes_<capture_instance>
. If the lsn_value
parameter is beyond the time of lowest LSN or highest LSN, then execution of these functions will return in error 313: Msg 313, Level 16, State 3, Line 1 An insufficient number of arguments were supplied for the procedure or function
. This error should be handled by the developer.