Hex characters in varchar() is actually ascii. Need to decode it.

Posted by csauve on Stack Overflow See other posts from Stack Overflow or by csauve
Published on 2010-05-25T19:42:28Z Indexed on 2010/05/25 20:01 UTC
Read the original article Hit count: 155

Filed under:
|
|
|
|

This is such an edge-case of a question, I'd be surprised if there is an easy way to do this.

I have a MS SQL DB with a field of type varchar(255). It contains a hex string which is actually a Guid when you decode it using an ascii decoder. I know that sounds REALLY weird but here's an example:

The contents of the field: "38353334373838622D393030302D343732392D383436622D383161336634396339663931"

What it actually represents: "8534788b-9000-4729-846b-81a3f49c9f91"

I need a way to decode this, and just change the contents of the field to the actual guid it represents. I need to do this in T-SQL, I cannot use .Net (which if I could, that is remarkably simple).

© Stack Overflow or respective owner

Related posts about sql

Related posts about encoding