Re: convert from hexadecimal to a decimal

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 10/01/04


Date: Fri, 01 Oct 2004 10:52:38 +0200

On Fri, 01 Oct 2004 03:35:26 -0400, Steve Kass wrote:

>Very good, and how about this?
>
>create function hexchar2(
> @b varchar(10)
>) returns int
>as begin
> return (
> select
>
>sum((charindex(right(left(@b,N),1),'123456789ABCDEF'))*POWER(16.,len(@b)-N))
> from numbers
> where n between 3 and len(@b))
> - case when lower(@b) like '0x[89abcdef]'+replicate('[0-9abcdef]',7)
> then 0x0100000000 else cast(0 as bigint) end
>end
>
>SK

Hi Steve,

Nice!

With the added advantage that it can be used inline in the query, so that
the overhad of calling a function is no longer incurred. (Though I would
comment it if I used it in a query <g>)

Best, Hugo

-- 
(Remove _NO_ and _SPAM_ to get my e-mail address)


Relevant Pages