It may not be obvious, but converting the binary to a char is not "toh". It's "toh" and 5 more CHAR(0) characters. Here is some code to show that:SELECT '[' + Convert(char(8), 0x746F680000000000, 0) + ']'SELECT REPLACE('[' + Convert(char(8), 0x746F680000000000, 0) + ']', CHAR(0), '_')SELECT '[' + CAST('toh' AS char(8)) + ']'SELECT REPLACE('[' + CAST('toh' AS char(8)) + ']', CHAR(0), '_')SELECT REPLACE('[' + Convert(char(8), 0x746F680000000000, 0) + ']', CHAR(0), '')
So, you can replace the CHAR(0) with a blank/empty string and they will then equal eath other:SELECT CASE WHEN REPLACE(Convert(char(8), 0x746F680000000000, 0), CHAR(0), '') = CAST('toh' AS char(8)) THEN 1 ELSE 0 END