Create Unique identifier from text

  • Hi,

    I have a text example given below :

    SPIT10IHOPIGACSystem

    SPMGS2IHOPIForecastingandPlanningProcess

    I need SPIT10IHOPIGACSystem to be converted to a UNIQUEIDENTIFIER (8-4-4-4-12) characters

    Desired result :SPIT10IH-OPIG-ACSy-stem-xxxxxxxxxxx -- add training x if not enough characters

    I need SPMGS2IHOPIForecastingandPlanningProcess

    to be converted to a UNIQUEIDENTIFIER (8-4-4-4-12) characters

    Desired result :SPMGS2IH-OPIF-orec-asti-ngandPlannin --Trim characters if more than required

    Thanks,

    PSB

  • What have you tried so far?

    What problems did you encounter?

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • The field where I am trying to insert is a UNIQUEIDENTIFIER and I am receiving the following error :

    Conversion failed when converting from a character string to uniqueidentifier

  • Phil, do we currently have a full moon? :w00t:



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • UNIQUEIDENTIFIER only permits hexadecimal digits, and your strings contain many non-hexadecimal characters.

    Exactly what is the goal of turning strings into UNIQUEIDENTIFIERS like this?

    Cheers!

  • I need to insert new rows into a table with fake UIDs . I was thinking of using this string to generate UID . How else can I auto generate UID ?

  • Got it!

    ALTER TABLE Table1 ADD CONSTRAINT DF_UID DEFAULT (NEWID()) FOR PUID;

    Thanks for the pointers.

  • Alvin Ramard (8/25/2016)


    Phil, do we currently have a full moon? :w00t:

    A very ordinary moon currently, it would seem 🙂

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • The field {columns are not fields} where I am trying to insert is a UNIQUEIDENTIFIER and I am receiving the following error

    Conversion failed when converting from a character string to uniqueidentifier

    The purpose of GUID and UUID is to locate something that is external to the database. It is never intended for internal use inside the schema. These are hexadecimal numbers that are long enough to be unique and they can be created by an algorithm.

    What are you actually trying to do? Why would you think that a string can be converted into a GUID? Were you looking for some kind of hashing algorithm?

    Books in Celko Series for Morgan-Kaufmann Publishing
    Analytics and OLAP in SQL
    Data and Databases: Concepts in Practice
    Data, Measurements and Standards in SQL
    SQL for Smarties
    SQL Programming Style
    SQL Puzzles and Answers
    Thinking in Sets
    Trees and Hierarchies in SQL

  • CELKO (8/25/2016)


    ... The purpose of GUID and UUID is to locate something that is external to the database. It is never intended for internal use inside the schema. ...

    Oh really? Never? I think I learned something new today. 😉



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

Viewing 10 posts - 1 through 9 (of 9 total)

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