I was recently working on a query where I had to convert a Character data to Binary and then later convert the Binary to Character data back again. Here’s how to do it.
We will assume that the character data with us is ‘SQLServer’
-- Convert Character to Binary
SELECT CONVERT(binary(9), 'SQLServer', 0) AS 'Char to Binary'
-- Convert Binary to Character
SELECT CONVERT(char(9), 0x53514C536572766572, 0) AS 'Binary to Char'