Luis Cazares - Monday, June 19, 2017 1:22 PM
The function fn_cdc_hexstrtobin has a check for the 0x prefix so there is no need for adding the prefix.
😎
I don't like this function, it is an old relic that has an input limitation of NVARCHAR(40) and returns VARBINARY(10), here is an ITVFN alternativeCREATE FUNCTION dbo.ITVFN_HEX_STR_TO_BIN
(
@HEX_STR NVARCHAR(MAX)
)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN
SELECT
CONVERT
(
VARBINARY(MAX)
,CONCAT
(
CASE
WHEN CHARINDEX(N'0x',@HEX_STR,1) = 1 THEN N''
ELSE N'0x'
END
,@HEX_STR
)
,1
) AS BIN_VAL
;