code_junkie

How can I print a binary value as hex in TSQL?

Nov 10th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. DECLARE @binvalue binary(4)
  2. SET @binvalue = 0x12345678
  3. PRINT CAST(@binvalue AS nvarchar)
  4.  
  5. print master.sys.fn_varbintohexstr(@binvalue)
  6.  
  7. DECLARE @binvalue binary(4)
  8. SET @binvalue = 0x61000000
  9. PRINT @binvalue
  10. PRINT cast('a' AS binary(4))
  11. PRINT cast(0x61 AS varchar)
  12.  
  13. DECLARE @mybin1 binary(16)
  14. DECLARE @s varchar(100)
  15. SET @mybin1 = 0x098F6BCD4621D373CADE4E832627B4F6
  16. SET @s = 'The value of @mybin1 is: ' + sys.fn_varbintohexsubstring(0, @mybin1,1,0)
  17. PRINT @s
  18.  
  19. sp_helptext 'fn_varbintohexsubstring'
Add Comment
Please, Sign In to add comment