Friday, October 30, 2009

SQL functions to convert between bases

So I had an application where I wanted to convert between decimal and hex values, and while I found a few ways to do this with SQL, they didn't really give me what I wanted (the varbinary datatype is NOT what I was looking for). The largest issue was that the way the javascript on my CRM form converted to hex and the way SQL converted to hex were apparently not the same, and it was very annoying.

Thankfully, I found a couple of fantastic blog posts that help with this. Mr. Caldwell has created 2 functions for converting into and out of different bases, and they work wonderfully (and the same way that javascript does):
Convert Decimal to any other base
Convert any base to Decimal

Note that these are designed for SQL 2005 or above - I was able to apply one of the functions to SQL 2000 by changing the varchar(max) to varchar(255) (which was large enough for me.

3 comments:

  1. Thanks a lot! I really appreciate your comment; I get very few of them so it's nice to know someone's getting something good out of my blog. If it's alright with you, I'd like to post this comment as a reply to your comment and link back to your blog.

    Sincerely,
    Patrick

    ReplyDelete
  2. Sorry for the delay publishing your comment - I get so few of them I had forgotten I had enabled moderating.

    ReplyDelete
  3. Cash development loan, along these lines, can work just for the situation you have an altered compensation and cash to pay on the following pay day. Thus, it is ideal to have your credit check finished by a rumored association before you present an application for a loan. It will help you in having a loan quickly.
    www.onlinenocreditcheckloans.co.uk

    ReplyDelete