0

I have some strange characters in a VARCHAR field which prevent me from converting the field into an INTEGER. I want to debug this and so I need an UDF that will convert the string to a hexadecimal code (just like in a hex editor) so that I can see which characters I am dealing with.

Where can I find such a function or how can I write it?

littlegreen
  • 7,290
  • 9
  • 45
  • 51

2 Answers2

5

Simple casting to varbinary would do the trick.

select cast( @string as varbinary(max)) 
Pavel Urbančík
  • 1,466
  • 9
  • 6
-3

And if you implement RULE and CHECK CONSTRAINTS in the, um, database, you can prevent strange characters getting into your fields in the first place. It is in the manual.

PerformanceDBA
  • 32,198
  • 10
  • 64
  • 90