Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

BASE64 Encode and Decode in T-SQL - optimized

By Aaron West,

This is just an optimized version of Daniel Payne's two scripts, base64_encode and base64_decode, with changes to end-of-block handling and a bug fix or two. If the encoded string ends in =, the last character is truncated. If ending in ==, two characters are chopped off. That seems better than replacing NUL characters with spaces, since base64 is used to encode binary data. The "reverse map" @rmap can be generated with the following code: /* commented to indicate this is only run once to help generate the code declare @map as char(64) SET @map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' declare @mapr as char(122) set @mapr = convert(binary(122),replicate(char(255),127)) declare @i int set @i = 0 while @i < 64 begin set @mapr = stuff(@mapr, ascii(substring(@map, @i + 1, 1)), 1, char(@i)) set @i = @i + 1 end set @mapr = stuff(@mapr, ascii('='), 1, CHAR(0)) select cast(@mapr as binary(122)) */

Total article views: 4132 | Views in the last 30 days: 5
 
Related Articles
FORUM

Variable Declaration

Variable Declaration

FORUM

Special Characters

removing special characters

FORUM

Special characters

search records with special characters.

FORUM

declaring global variables

declaring global variables

FORUM

Character Field Declaration

Comments posted to this topic are about the item [B]Character Field Declaration[/B] Nice question - ...

Tags
miscellaneous    
 
Contribute