Re: DEC TO HEX CONVERSION WHILE IMPORTING

From: Steve Kass (skass_at_drew.edu)
Date: 05/13/04

  • Next message: MUSTAFA: "Re: DEC TO HEX CONVERSION WHILE IMPORTING"
    Date: Thu, 13 May 2004 02:26:49 -0400
    
    

    Mustafa,

      If your decimal values fit into a bigint, you could write a
    user-defined function (SQL Server 2000 required):

    create function dec2hex (
      @decimal bigint
    ) returns varbinary(20) as begin
      declare @b varbinary(20)
      set @b = 0x
      while @decimal > 0 begin
        set @b = cast(cast(@decimal%256 as tinyint) as binary(1)) + @b
        set @decimal = @decimal/256
      end
      return @b
    end
    go

    select dbo.dec2hex(1)
    select dbo.dec2hex(2571551874.0)

    go
    drop function dec2hex

    -- Steve Kass
    -- Drew University
    -- Ref: 77AF63E1-A927-40A1-A7B0-6EA31F1C80F2

    MUSTAFA wrote:

    >I HAVE DECIMAL NUMBER IN MY TEST TABLE COLUMN CARD_NUMBER
    >AS FOLLOWS
    >2571549730.0
    >2571549826.0
    >2571550034.0
    >2571550210.0
    >2571550306.0
    >2571551378.0
    >2571551586.0
    >2571551682.0
    >2571551762.0
    >2571551874.0
    >
    >I WANT TO CREATE A TEMP TABLE AND MOVE THIS COLUMN BUT
    >BEFORE MOVING IT SHOULD CONVERT INTO HEXADECIMAL NUMBER
    >WHILE INSERTING INTO TEMP TABLE
    >
    >
    >THANKS
    >
    >


  • Next message: MUSTAFA: "Re: DEC TO HEX CONVERSION WHILE IMPORTING"