Tutorial :SQL Base32 Conversion


I am writing a SQL Function that will take in a decimal and return the base32 representation of that decimal.

My problem is with the decimal to ascii conversion.

I am allowed to run the following query and return an ascii character

"SELECT CHAR( 65 )" which returns "A"

However in my function when I am trying to build my output string of letters, I am having trouble casting a bigint into a char, then concatenate that char to the end of a another char(which would be my output).

Sample line of code: "SET @OutputChar = @OutputChar + CAST( ( @Output + 55 ) AS CHAR(255) )"

What is the proper way to cast a bigint to char and then concatenate that char to another?



How are you declaring @OutputChar?

If you have:

DECLARE @OutputChar CHAR(255)  

then every time you concantenate, it will truncate it to 255. CHAR includes the whitespace at the end, maybe you mean to use varchar instead of CHAR?


Try this:

SET @OutputChar = @OutputChar + CONVERT(varchar(255),@Output + 55)  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »