0

When I do a select statement for varbinary field in microsoft enterprise manager i get the field on readabel hex format like ab2c2f2d... but when i do the same statment with pymssql i get a gibrish

the select statment is : select x from table --where x the varbinary field

could someone help with this issue ?

Stephane Rolland
40.2k38 gold badges128 silver badges173 bronze badges
asked Feb 23, 2010 at 17:38
2
  • You are not getting "a gibrish", you are getting the raw binary data. Commented Feb 23, 2010 at 17:51
  • But how i can convert it to hex format like what shown in microsoft enterprise manager Commented Feb 23, 2010 at 17:52

1 Answer 1

2

Microsoft Enterprise Manager is converting the binary value to a hexadecimal string for you.

One option is to change your query to SELECT CAST( x AS varchar ) FROM table. This will have SQL Server convert the varbinary to a hexdecimal string for you, http://msdn.microsoft.com/en-us/library/aa226054(SQL.80).aspx

Another option is to use the python module, binascii to convert the binary data to a hexadecimal string yourself. You use the functions binascii.b2a_hex(data) or binascii.hexlify(data) to do this.

answered Feb 23, 2010 at 18:05
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.