Re: convert from hexadecimal to a decimal

From: Steve Kass (skass_at_drew.edu)
Date: 10/29/04


Date: Thu, 28 Oct 2004 20:17:10 -0400

Hugo,

  Don't forget that if you want something that can be put inline without
a UDF call, you can use something more like 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

Hugo Kornelis wrote:

>On Wed, 27 Oct 2004 19:31:12 -0500, landung wrote:
>
>
>
>>hi all,
>>
>>when i run this query, it will result this :
>>
>>Server: Msg 207, Level 16, State 3, Procedure hexchar2, Line 5
>>Invalid column name 'n'.
>>
>>May i know the 'n' factor is ???
>>
>>
>
>Hi landung,
>
>It's a column in the numbers table I used for this query.
>
>If you don't have a numbers table yet, check out this link:
>http://www.aspfaq.com/show.asp?id=2516
>
>If you do have a numbers table, but with another column name, change the
>query to reflect the names of your numbers table and column.
>
>Best, Hugo
>
>



Relevant Pages

  • Re: Performance considerations UDF vs Joins
    ... >>FROM (A INNER JOIN ... The UDF certainly makes things ... >Are you sure you made no errors when copying the query in your message? ... >a seperate read in the lookup table has to be performed. ...
    (microsoft.public.sqlserver.programming)
  • Re: Any way to force a recompile on a statement within a User Defined Function?
    ... Can you wrap the query in the UDF inside sp_executesql? ... that way each different value for c2 will have a different plan. ... Wayne Snyder, MCDBA, SQL Server MVP ...
    (microsoft.public.sqlserver.server)
  • Re: SQL Server Performance Issue
    ... when your run the UDF ... Dual-Core Woodcrest 1.6Ghz, 2GB RAM, IIS, SQL Server). ... Physical Disk Reads and Writes when i execute this example UDF query, ... Server has a SATA RAID1 Disk Mirroring ...
    (comp.databases.ms-sqlserver)
  • Re: User-defined functions in where clause
    ... UDF is used to row by row process similar how cursors work. ... avoid using udf with large set result. ... > create function ZeroTime(@Date datetime) ... > Run this query in query analyzer with the server trace option on and you ...
    (microsoft.public.sqlserver.programming)
  • Re: Performance considerations UDF vs Joins
    ... Not because SP will perform better than queries, ... give them only execute permission on stored procedures that will ... In UDF: no. ... In fact, a query using inline ...
    (microsoft.public.sqlserver.programming)