Select[Current LSN],[Previous LSN],Operation,Context,[Transaction Name],*
From fn_dblog(null,null)
where [Begin Time]>'2025/01/15'--转换fn_dblog的十六进制Current LSN格式Declare @LSN varchar(22),@LSN1 varchar(11),@LSN2 varchar(10),@LSN3 varchar(5),@NewLSN varchar(26)-- LSN to be converted to decimalSet @LSN='00000155:0000c7d8:0001';-- Split LSN into segments at colonSet @LSN1=LEFT(@LSN, 8);Set @LSN2=SUBSTRING(@LSN, 10, 8);Set @LSN3=RIGHT(@LSN, 4);-- Convert to binary style 1 -> intSet @LSN1=CAST(CONVERT(VARBINARY,'0x'+RIGHT(REPLICATE('0', 8)+@LSN1, 8), 1) As int);Set @LSN2=CAST(CONVERT(VARBINARY,'0x'+RIGHT(REPLICATE('0', 8)+@LSN2, 8), 1) As int);Set @LSN3=CAST(CONVERT(VARBINARY,'0x'+RIGHT(REPLICATE('0', 8)+@LSN3, 8), 1) As int);-- Add padded 0's to 2nd and 3rd stringSelect CAST(@LSN1 as varchar(8))+CAST(RIGHT(REPLICATE('0', 10)+@LSN2, 10) as varchar(10))+CAST(RIGHT(REPLICATE('0', 5)+@LSN3, 5) as varchar(5));
转载:
转换fn_dblog的十六进制Current LSN格式-CSDN博客
参考:
SQL varbinary, substring, char to binary,fn_dblog 以及 log 中的 binary 杂记_varbinary substring-CSDN博客