I (have to) use base64Binary
to convert my base64 encoded string into bytes. In most cases it works good enough, but from time to time it returns NULL .
For example this works like a charm:
DECLARE @Base64String VARCHAR(MAX)
SET @Base64String = 'qwerqwerqwerqwer'
declare @Base64Binary VARBINARY(MAX)
set @Base64Binary = cast('' as xml).value('xs:base64Binary(sql:variable("@Base64String"))', 'VARBINARY(max)');
select @Base64Binary as 'base64'
Result is 0xAB07ABAB07ABAB07ABAB07AB
and that's ok for me.
But if I set SET @Base64String = 'qwerqwerqwerqwe='
then I get NULL
as result. Why? I pass pretty valid base64 string and expect not null value. I've tried to find some workaround, but no luck. How can I made xs:base64Binary
to return valid varbinary value for such input strings?