Inverse -- Reverse

  • Hi,

    I am not able to slove my problem so guys i need ur help.

    i had (thousands) of records in my database in this manner.

    Name Id

    DFDDABBF-7079-4135-AAD8-1BDA58DB0CEB

    Now i need the Nameid like below

    BFABDDDF-7970-3541-AAD8-1BDA58DB0CEB

    I need changes till 18 character started from left handside.

    Thanx for ur help.

    from

    Killer

  • Is it uniqueidentifier?

    _____________
    Code for TallyGenerator

  • Yes it is.

     

    from

    Killer

  • Is there a reason why you can't just use substring? Like this...

    --This SQL script is safe to run

    DECLARE @t TABLE (Id INT IDENTITY, Name_Id UNIQUEIDENTIFIER)

    INSERT @t

          SELECT 'DFDDABBF-7079-4135-AAD8-1BDA58DB0CEB'

    UNION SELECT NEWID()

    UNION SELECT NEWID()

    SELECT * FROM @t

    SELECT

        Id,

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 7, 2) +

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 5, 2) +

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 3, 2) +

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 1, 2) +

        '-' +

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 12, 2) +

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 10, 2) +

        '-' +

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 17, 2) +

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 15, 2) +

        SUBSTRING(CAST(Name_Id AS VARCHAR(40)), 19, 20)

    FROM

        @t

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • If it's uniqueidentifier then it's not varchar, it's binary(16).

    Treat it as it is, not as it seems to you.

    P.S. Substring works for binary strings as well.

    _____________
    Code for TallyGenerator

  • Hi Sergily,

     

    It is in binary ex:0x...... but i removed 0x from the bignning of the records, i transfered the record in a varchar field as written above.

    I am not  good at programming i need the data like this

    Q: ABVFHG-1234-4563-ASDEFF-2345-5673

    Ans : HGVFAB-3412-6345-ASDEFF -2345-5673

     

    from

    Killer

  • Hi,

    Thanx a lot , it run so well.

     

    from

    Killer

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply