1. CREATE FUNCTION fn_hexstrtovarbin(@input varchar(8000))
  2. returns varbinary(8000)
  3. AS
  4. begin
  5. declare @result varbinary(8000)
  6.  
  7. IF @input IS NOT NULL
  8. begin
  9. declare @i int, @l int
  10.  
  11. SELECT @result = 0x, @l = len(@input) / 2, @i = 2
  12.  
  13. while @i <= @l
  14. begin
  15. SET @result = @result +
  16. cast(cast(case lower(substring(@input, @i*2-1, 1))
  17. when '0' then 0x00
  18. when '1' then 0x10
  19. when '2' then 0x20
  20. when '3' then 0x30
  21. when '4' then 0x40
  22. when '5' then 0x50
  23. when '6' then 0x60
  24. when '7' then 0x70
  25. when '8' then 0x80
  26. when '9' then 0x90
  27. when 'a' then 0xa0
  28. when 'b' then 0xb0
  29. when 'c' then 0xc0
  30. when 'd' then 0xd0
  31. when 'e' then 0xe0
  32. when 'f' then 0xf0
  33. end AS tinyint) |
  34. cast(case lower(substring(@input, @i*2, 1))
  35. when '0' then 0x00
  36. when '1' then 0x01
  37. when '2' then 0x02
  38. when '3' then 0x03
  39. when '4' then 0x04
  40. when '5' then 0x05
  41. when '6' then 0x06
  42. when '7' then 0x07
  43. when '8' then 0x08
  44. when '9' then 0x09
  45. when 'a' then 0x0a
  46. when 'b' then 0x0b
  47. when 'c' then 0x0c
  48. when 'd' then 0x0d
  49. when 'e' then 0x0e
  50. when 'f' then 0x0f
  51. end AS tinyint) AS BINARY(1))
  52. SET @i = @i + 1
  53. end
  54. end
  55.  
  56. RETURN @result
  57. end
  58.  
* IE¿¡¼­ ¼Ò½º º¹»ç½Ã ÁÙ¹Ù²Þ ¾ÈµÊ. MS-Word µî¿¡ ºÙ¿© ³ÖÀ¸¼¼¿ä. ÁÙ¹Ù²Þ µÇ´Â ºê¶ó¿ìÀú: Chrome, Opera, Safari