updating a field with unique 15 digit navarchar

  • is there anyway i can update a nvarchar field with unique 15 digit nvarchar ? i cant seem to find an answer online. Any clues guys.

  • Yes but why are you using NVARCHAR to store "digits"? Also, you've not stated the full datatype for the column. NVARCHAR(???) ? And, what do you want to update it to and from?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff,

    It is a UserId field with i.e. userID nvarchar(15). We have to have a unique alphanumeric values for all userID's.

    thanks,

  • Would this work?

    LEFT(REPLACE(CAST(NEWID () AS NVARCHAR(MAX)), '-', '') , 15)



    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]

  • Alvin Ramard (8/25/2016)


    Would this work?

    LEFT(REPLACE(CAST(NEWID () AS NVARCHAR(MAX)), '-', '') , 15)

    I'm not sure if that will return unique strings. Although, the chance for duplicates is low.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (8/25/2016)


    Alvin Ramard (8/25/2016)


    Would this work?

    LEFT(REPLACE(CAST(NEWID () AS NVARCHAR(MAX)), '-', '') , 15)

    I'm not sure if that will return unique strings. Although, the chance for duplicates is low.

    Good point Luis. A Unique constraint could easily prevent duplicates.



    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 6 posts - 1 through 5 (of 5 total)

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