After referring to the question Base64 encoding in SQL Server 2005 T-SQL, I tried to get the base64 values for some data from sql table but it's not giving proper values when compared to direct text values.
Using Direct text:
SELECT CAST('?' as varbinary) FOR XML PATH(''), BINARY BASE64
gives value as Pw==
which is correct and it decodes to ?
Using Database entry:
SELECT CAST([Col] as varbinary) from tblTable FOR XML PATH(''), BINARY BASE64
with [Col]
value = ?
, gives output as PwA=
which when decoded gives ? and an extra non-printable character.
Screenshot when checked using len function.
The reason for this is that I want to convert data for few columns from plain text to base64 using update statement, this is just sample value and actual values are bigger text which is also having this problem but with every character.
Edit: This when decoded from ASP.Net, if it's on label then it displays properly but when used in textbox shows extra junk characters.