I\'d like to write a T-SQL query where I encode a string as a Base64 string. Surprisingly, I can\'t find any native T-SQL functions for doing Base64 encoding. Does a nativ
The simplest and shortest way I could find for SQL Server 2012 and above is BINARY BASE64 :
SELECT CAST('string' as varbinary(max)) FOR XML PATH(''), BINARY BASE64
For Base64 to string
SELECT CAST( CAST( 'c3RyaW5n' as XML ).value('.','varbinary(max)') AS varchar(max) )
( or nvarchar(max)
for Unicode strings )