Ok, so the padded 00 has been answered.
DECLARE @hexStringNVar nvarchar(max)
DECLARE @hexStringVAR varchar(max)
SET @hexStringNVar = '{my hex string as described above}'
SET @hexStringVAR = '{my hex string as described above}'
select CONVERT(varbinary(MAX), @hexStringNVar)) = 0x6100700070006C00690063...
select CONVERT(varbinary(MAX), @hexStringVAR)) = 0x6170706C6963...
The 00
padding is because of Unicode or NVARCHAR
as opposed to VARCHAR
.
So, since the stored data is in nvarchar(max)
, the solution is this:
select CAST(cast(@hexStringNVar as varchar(max)) as varbinary(max)) = 0x6170706C6963...
I'm sure that convert
would work just as well but my target SQL Server is 2005.