I'm using SQL Server 2000 to print out some values from a table using PRINT
. With most non-string data, I can cast to nvarchar to be able to print it, but binary values attempt to convert using the bit representation of characters. For example:
DECLARE @binvalue binary(4)
SET @binvalue = 0x12345678
PRINT CAST(@binvalue AS nvarchar)
Expected:
0x12345678
Instead, it prints two gibberish characters.
How can I print the value of binary data? Is there a built-in or do I need to roll my own?
Update: This isn't the only value on the line, so I can't just PRINT @binvalue. It's something more like PRINT N'other stuff' + ???? + N'more stuff'. Not sure if that makes a difference: I didn't try just PRINT @binvalue by itself.